I'm trying to determine if user is logged in (Flutter Firebase) using FirebaseAuth.instance.currentUser, and then return LoginScreen or Dashboard, but getting an error. I tried to write code based on instructions from FirebaseFlutter, but those seems to be deprecated...
Widget build(BuildContext context) {
return FutureBuilder<User>(
future: FirebaseAuth.instance.currentUser,
builder: (BuildContext context, AsyncSnapshot<User> snapshot) {
if (snapshot.hasData) {
User user = snapshot.data;
/// is because there is user already logged
return Dashboard();
}
/// other way there is no user logged.
return LoginScreen();
});
}
I'm getting an error in 3rd line future: ... that stands for The argument type 'User' can't be assigned to the parameter type 'Future<User>'. Please may anyone explain to me how should I do this, and what I'm doing wrong?
I tried to pass that in function ()=> but it still not work...
Currently using firebase_auth: 0.20 and firebase_core 0.7