android - Flutter Firebase Error Null fundtion(FirebaseUser)无法分配给参数,仪表类型 FutureOr <dynamic>

标签 android firebase flutter dart firebase-authentication

在我的 Firebase 身份验证中,我遇到了错误:

error: The argument type 'Null Function(FirebaseUser)' can't be assigned to the parameter type 'FutureOr Function(AuthResult)'. (argument_type_not_assignable at [authentication] lib\loginpage.dart:44)

如果导入 firebase_auth 和 flutter Material

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

最佳答案

查看插件源码函数

.signInWithEmailAndPassword()

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

.then((FirebaseUser user)

应该改为

.then((AuthResult auth)

可以看到here

关于android - Flutter Firebase Error Null fundtion(FirebaseUser)无法分配给参数,仪表类型 FutureOr <dynamic>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57411112/

相关文章:

reactjs - React-redux 与 re-base-firebase。好主意?

php - 推送通知服务器端实现

typescript - Firebase Admin SDK错误: Expression has type `void` .将其作为语句放在自己的行中

Flutter 桌面多显示器

flutter - Q : How to run flutter app on device without usb or connecting to computer

android - 添加新语言环境并在 Android 应用程序中强制使用语言环境(本地化)

android - AsyncTask 和 Activity 怎么做

android以编程方式设置按钮背景

java - 如何在滚动时将数据加载到 RecyclerView 中

Flutter : PageController. 页面在使用它构建 PageView 之前无法访问