[英]Flutter FirebaseAuth: How can i check if a User is LoggedIn in a void?
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.我是 FirebaseAuth 的新手,我希望它检查用户是否已登录,如果没有,他将被重定向。
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 中检查用户 os LoggedIn:
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!谢谢!
Maybe using the currentUser
synchronous getter would be enough?也许使用
currentUser
同步 getter 就足够了?
if (FirebaseAuth.instance.currentUser != null) {...}
ref: https://pub.dev/documentation/firebase_auth/latest/firebase_auth/FirebaseAuth/currentUser.html参考: https://pub.dev/documentation/firebase_auth/latest/firebase_auth/FirebaseAuth/currentUser.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.