firebase - 我收到一个错误 NoSuchMethodError: The method currentUser was called on null.FLUTTER
问题描述
我正在尝试检查用户是否已登录,我已使用 firebase 验证了我的颤振应用程序,我希望用户的状态将应用程序重定向到登录页面或主页,但我无法运行该应用程序在红屏上显示错误,错误是:NoSuchMethodError:方法'currentUser'被调用为null。接收方:null 尝试调用:currentUser()
我在这里看到了解决方案, 但我没有正确理解
当前用户功能:
Future<String> currentUser() async {
FirebaseUser user = await _firebaseAuth.currentUser();
return user!= null ? user.uid : null;
}
检查身份验证状态:
void initState() {
super.initState();
try {
widget.auth.currentUser().then((userId) {
setState(() {
authStatus =
userId == null ? AuthStatus.notsignedIn : AuthStatus.signedIn;
});
});
} catch (e) {}
}
解决方案
该错误仅表示您的_firebaseAuth
对象为空。尝试使用
FirebaseUser user = await FirebaseAuth.instance.currentUser();
推荐阅读
- matlab - E(1,:)*c 和 E(1,:)*c(1,:) 有什么区别
- c# - Dotnet Sonar Scanner for ubuntu 错误“进程终止。找不到系统上安装的有效 ICU 包”
- java - Java Discord4j如何将消息发送到通道REST API?
- apache-flink - WatermarkGenerator#onEvent 方法签名中的 eventTimestamp 似乎是多余的
- android - 在 org.gradle.api.Project 类型的根项目“android”上找不到参数 [build_1c6nueis8xobld9$_run_closure2@7bfda345] 的方法 android()
- python - Python Excel文件到字典
- haskell - Haskell Lambda 函数
- reactjs - TypeError:无法解构“panelMembersList”的属性“错误”,因为它未定义
- graph - 如何更新 Gremlin 中的顶点/边 ID?
- mysql - 将字符串原始查询的 OrderBy 列表转换为 jpa 查询