首页 > 解决方案 > 使用 Flutter 进行 Firebase 身份验证

问题描述

Flutter Android Firebase authentication Error, The Authentication pass through but error in the terminal 虽然应用程序没有失败

[错误:flutter/lib/ui/ui_dart_state.cc(148)] 未处理的异常:NoSuchMethodError:在 null 上调用了 getter 'uid'。

错误似乎来自这行代码

Future<String> currentUser() async {
    FirebaseUser user = await _firebaseAuth.currentUser();
    return user.uid;
}

标签: flutter

解决方案


的结果_firebaseAuth.currentUser()为空。通常这意味着您根本没有登录。

在访问当前用户之前,请确保您已登录。例如使用电子邮件凭据:

await _firebaseAuth.signInWithEmailAndPassword(email:'email@here.com', password: 'abc123');

好消息是firebase包会缓存当前用户,所以在你登录后你暂时不用再做一次,你可以简单地调用你的currentUser方法。


推荐阅读