I tried maybe 4 different ways to write the code for toggling between the sign in page and the register page using a toggle function but it always gave me an error but this type doesn't give me an error in the code it prints an error in the run console that says "The following _CastError was thrown while handling a gesture: Null check operator used on a null value"
This is my authentication file 'authenticate.dart':
class _AuthenticateState extends State<Authenticate> {
bool showSignIn = false;
void Function()? toggleView() {
setState(() => showSignIn = !showSignIn);
}
@override
Widget build(BuildContext context) {
if(showSignIn) {
return SignIn(toggleView: toggleView());
} else {
return Register(toggleView: toggleView());
}
}
}
This is my 'register.dart' file:
class Register extends StatefulWidget {
final void Function()? toggleView;
Register({ required this.toggleView});
@override
_RegisterState createState() => _RegisterState();
}
class _RegisterState extends State<Register> {
final AuthService _auth = AuthService();
//text field state
String email = '';
String password = '';
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.brown[100],
appBar: AppBar(
backgroundColor: Colors.brown[400],
elevation: 0,
title: Text('Sign up to the breakfast club'),
actions: [
TextButton.icon(
icon: Icon(
Icons.person,
),
label: Text('Sign In'),
onPressed: () {
print('Sign in clicked');
widget.toggleView!();
},
style: TextButton.styleFrom(
primary: Colors.white,
),
),
And my 'sign_in.dart' is exactly the same as 'register.dart' except for this part:
onPressed: () {
print('Register clicked');
widget.toggleView!();
},