I am trying to navigate to my home page or login page on the basis of authStatus. While using Navigator.of(context)... it returns null on the build method for a second and then screen refreshes and navigate to the given page successfully. I am relatively new to mobile development and flutter. Any leads will help! Thanks.
Here is the code:
@override
Widget build(BuildContext context) {
switch (authStatus) {
case AuthStatus.NOT_LOGGED_IN:
WidgetsBinding.instance.addPostFrameCallback((_) {
{
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LoginSignUpPage(
auth: widget.auth,
onSignedIn: _onLoggedIn,
params: widget.params,
)),
);
}
});
break;
case AuthStatus.LOGGED_IN:
if (_userId.length > 0 && _userId != null) {
WidgetsBinding.instance.addPostFrameCallback((_) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomePage(
userId: _userId,
auth: widget.auth,
onSignedOut: _onSignedOut,
params: widget.params,
)),
);
});
} else
return widget.waitingScreen;
break;
default:
return widget.waitingScreen;
}
Here is the error :
A build function returned null. The offending widget is: RootPage Build functions must never return null. To return an empty space that causes the building widget to fill available room, return "Container()". To return an empty space that takes as little room as possible, return "Container(width: 0.0, height: 0.0)".
on the code line following WidgetsBinding, add
return Container();
You could also include a color parameter to match your design.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With