如何解决如果 currentUser() 已弃用,我该如何使用 .then?
因为我刚刚学习颤振和 我有点关注旧视频,所以大部分 firebase 代码都被弃用了。
firebaseAuth.currentUser.then((user){
if(user != null){
setState(() => isLoggedIn = true);
}
});
解决方法
获得currentUser
实际上变得更容易了。现在它不是未来,因此您不必await
或使用then
。您可以这样获取用户:
final user = firebaseAuth.currentUser;
if(user != null){
setState(() => isLoggedIn = true);
}
,
试试这个
FirebaseAuth.instance.authStateChanges().listen((User user) {
if (user == null) {
print('User is currently signed out!');
} else {
print('User is signed in!');
}
});
https://firebase.flutter.dev/docs/auth/usage/#authentication-state
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。