i am trying to make sure the app knows if the user is logged in or not. if they are logged in, then they are redirected to the home page. if not they are brought to the landing page.
the app seems to work fine if i just restart the entire app or just close the app without removing it from task. however if i remove close the app and remove the app from task. it brings me to the landing page while, in fact, the user is still logged in.
the following is what i use to determine if the user is logged in, if so they are redirected to the home page, otherwise, landing page.
class LandingOrHome extends StatefulWidget {
@override
_LandingOrHomeState createState() => _LandingOrHomeState();
}
class _LandingOrHomeState extends State<LandingOrHome> {
var onlineCurrentUser;
FirebaseUser getCurrentUser() {
FirebaseAuth.instance.currentUser().then((currentUser) {
if (currentUser != null) {
onlineCurrentUser = currentUser;
}
});
if (onlineCurrentUser != null) return onlineCurrentUser;
return null;
}
@override
Widget build(BuildContext context) {
if (getCurrentUser() != null)
return HomeScreen();
else
return LandingScreen();
}
}
main.dart
//...
home: LandingOrHome()