![](/img/trans.png)
[英]Flutter/FirebaseAuth : How can I autologin a user at app launch?
[英]Flutter FirebaseAuth: How can i check if a User is LoggedIn in a void?
我是 FirebaseAuth 的新手,我希望它檢查用戶是否已登錄,如果沒有,他將被重定向。
那是我的空白:
void newEntry() {
showDialog<AlertDialog>(
context: context,
builder: (BuildContext context) {
return neuerEintrag(addItem);
});
}
這是我在另一個 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();
},
);
}
}
謝謝!
也許使用currentUser
同步 getter 就足夠了?
if (FirebaseAuth.instance.currentUser != null) {...}
參考: https://pub.dev/documentation/firebase_auth/latest/firebase_auth/FirebaseAuth/currentUser.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.