Reputation: 281
I am new in FirebaseAuth and i want, that in a void it check if the User is LoggedIn and if not, that he will be redirected.
That is my void:
void newEntry() {
showDialog<AlertDialog>(
context: context,
builder: (BuildContext context) {
return neuerEintrag(addItem);
});
}
And this is my check if the User os LoggedIn, in an other class:
class loginProfile extends StatelessWidget {
@override
Widget build(BuildContext context) {
final AuthService auth = Provider.of(context).auth;
return StreamBuilder<String>(
stream: auth.onAuthStateChanged,
builder: (context, AsyncSnapshot<String> snapshot) {
if (snapshot.connectionState == ConnectionState.active) {
final bool signedIn = snapshot.hasData;
return signedIn ? Profil() : FirstView();
}
return CircularProgressIndicator();
},
);
}
}
Thanks!
Upvotes: 0
Views: 37
Reputation: 8393
Maybe using the currentUser
synchronous getter would be enough?
if (FirebaseAuth.instance.currentUser != null) {...}
ref: https://pub.dev/documentation/firebase_auth/latest/firebase_auth/FirebaseAuth/currentUser.html
Upvotes: 2