【发布时间】:2023-03-07 04:03:01
【问题描述】:
我有这段代码应该返回用户 ID。问题是它返回 null 因为用户已注销。
@override
void initState() {
// TODO: implement initState
super.initState();
try {
widget.auth.currentUser().then((userId) {
setState(() {
authStatus = userId == null ? AuthStatus.notSignedIn : AuthStatus.signedIn;
});
});
} catch (e) {}
}
即使在它周围包裹了一个 catch 块之后,它仍然会引发错误。该错误冻结了我的应用程序 错误:
Exception has occurred.
NoSuchMethodError: The getter 'uid' was called on null.
Receiver: null
Tried calling: uid
试图调用的方法是
Future<String> currentUser() async {
FirebaseUser user = await _firebaseAuth.currentUser();
return user.uid;
}
【问题讨论】: