Flutter Firebase错误Null资助(FirebaseUser)无法分配给参数,仪表类型FutureOr <dynamic>

时间:2019-08-08 11:04:17

标签: android firebase flutter dart firebase-authentication

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

  

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

如果importfirebase_auth和flutter材质

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

2 个答案:

答案 0 :(得分:1)

查看插件的源代码功能

$scope.treeData.view()

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

.signInWithEmailAndPassword()

应改为

.then((FirebaseUser user)

您可以看到它here

答案 1 :(得分:0)

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