I'm trying to navigate to another screen from the first one, so basically, I'm checking if the user is logged in or not and based on that I navigate or not to the next screen, but I'm getting an error of a context while trying that
This is my code
Future _AuthenticateUser(BuildContext context){
FirebaseAuth.instance
.authStateChanges()
.listen((event) {
if(event == null){
// User is null
} else {
// here I navigate to the next screen
Navigator.push(context,
MaterialPageRoute(builder: (context) => new MainScreen()));
}
});
}
I'm calling the code at first to check for user logging state
@override
void didChangeDependencies() {
_AuthenticateUser(context);
super.didChangeDependencies();
}
This is the error i'm getting
The context used to push or pop routes from the Navigator must be that of a widget that is a descendant of a Navigator widget.