I want to add a simple feature in my flutter app :
Future<dynamic> showTextFieldDialog(BuildContext context) {
return showDialog(
context: context,
builder: (BuildContext context) {
return DemoRegisterDialog();
},
);
}
This dialog returns a custom widget that contains a button that returns this when clicked :
onPressed: () async {
Navigator.pop(context);
await _authService.loginUser(context);
if (_firebaseAuth.currentUser != null) {
Future.delayed(Duration(seconds: 2), () {
Navigator.pushNamed(context, MainPage.id);
});
}
};
So the idea here is quite simple : when the button is clicked, it should close the dialog, trigger the login, and then navigate to the next screen if the login is successful.
But I keep getting this error :
external static Never _throw(Object error, StackTrace stackTrace);
_TypeError (Null check operator used on a null value)
The login function works fine, the issue comes from the combination of Navigator.pop(context);
and Navigator.pushNamed(context, MainPage.id);
If I remove one them, it’s working fine.
I tried to delay the navigation, tried different types of navigators but keep getting this error.
What Am I missing here ?