【问题标题】:Flutter Firebase Error Null fundtion(FirebaseUser) cant assigned to parame,meter type FutureOr<dynamic>Flutter Firebase 错误 Null 资金(FirebaseUser)无法分配给参数,仪表类型 FutureOr<dynamic>
【发布时间】:2019-12-16 01:51:19
【问题描述】:

在我的 Firebase 身份验证中,我面临错误:

错误:参数类型“Null Function(FirebaseUser)”不能是 分配给参数类型'FutureOr 函数(AuthResult)'。 (argument_type_not_assignable 在 [认证] lib\loginpage.dart:44)

如果导入 firebase_auth 和颤振材料

            onPressed: (){
              FirebaseAuth
              .instance
                  .signInWithEmailAndPassword(
                email: _email,
                password: _password
              ).then((FirebaseUser user){
                Navigator.of(context).pushReplacementNamed('/homepage');
              })
                  .catchError((e){
                    print(e);
              });
            }

【问题讨论】:

  • 问题似乎在这里.then((FirebaseUser user) 你确定 FirebaseAuth 实例返回一个 FirebaseUser 对象吗?使用调试器断点查看它返回的内容。

标签: android firebase flutter dart firebase-authentication


【解决方案1】:

查看插件函数的源码

.signInWithEmailAndPassword()

是一个返回 AuthResult 的 Future,所以问题出在你的回调方法中

.then((FirebaseUser user)

应该是

.then((AuthResult auth)

你可以看到here

【解决方案2】:
onPressed: () {
                  FirebaseAuth.instance
                      .signInWithEmailAndPassword(
                          email: _email, password: _password)
                      .then((value) {
                    Navigator.of(context).pushReplacementNamed('/homepage');
                  }).catchError((e) {
                    print(e);
                  });
                },

试试这个,它会起作用的。如果您有 multidex 错误,请参考此链接 https://developer.android.com/studio/build/multidex#java

【讨论】:

    猜你喜欢
    • 2019-04-27
    • 2022-11-28
    • 2021-12-27
    • 1970-01-01
    • 1970-01-01
    • 2020-12-27
    • 1970-01-01
    • 1970-01-01
    • 2022-11-22
    相关资源
    最近更新 更多