首页 > 解决方案 > Flutter:尝试在空对象引用上调用虚拟方法

问题描述

我目前在尝试允许用户使用 Firebase 身份验证通过我的应用程序创建帐户时遇到问题。方法:createUserWithEmailAndPassword()

错误:尝试在空对象引用上调用虚拟方法 'com.google.android.gms.tasks.Task com.google.firebase.auth.FirebaseAuth.createUserWithEmailAndPassword(java.lang.String, java.lang.String)'

我不得不将我的应用程序迁移到 Android X,因为我使用 Firestore 作为我的数据库,并且在测试帐户创建之前一切都运行良好。我已经尝试了从更改 build.gradle 文件中的依赖项到更改 pubspec.yaml 文件中插件版本的所有方法。没有任何工作。我还在 Firebase 控制台中启用了使用电子邮件和密码登录。

当前使用的 Pubspec 插件:

  http: ^0.12.0+2
  cloud_firestore: ^0.9.0
  google_sign_in: ^4.0.1+3
  firebase_auth: ^0.9.0
  location: "^2.3.5"
  geolocator: ^4.0.0

Firebase 身份验证代码:

FirebaseAuth _auth = FirebaseAuth.instance;
 Future<FirebaseUser> handleRegistration (String *,
  String *,String *, String *, String *,
  String *, String *, String *, String *, 
  String *, String *, String *,
  String medName, String medNum, String emrgName, 
  String emrgNum,  String emailAdd,String password) async{
    try{
      final FirebaseUser user = await _auth.createUserWithEmailAndPassword(email: emailAdd,password: password);
      assert(user != null);
      assert(await user.getIdToken()!= null);
      if(user!= null){
        getLocation();
      if(await user.getIdToken() != null){
        if(isMember == "Yes"){
          String validateMembership = checkUsersClubReg(user.uid, clubName);
          if(validateMembership == "Active"){
            var clubDetails = validateMembership.split(',');
            createUsersAccount(*, *, *, *, *,
             *, *, *, *, *, *, "*",
              *, user.uid, medName, medNum, emrgName, emrgNum,"Inactive","0" );
          }else{
            createUsersAccount(*, *, *, *, *,
             *, *, *, *, *, *, "*",
              *, user.uid, medName, medNum, emrgName, emrgNum,"Inactive","0");
          }
        }
      }
      return user;
    }
    }on AuthException catch(ex){
      print(ex.code.toString());

    }
  }

预期结果:将用户帐户写入 Firebase 身份验证实际结果:代码中断,错误:尝试调用虚拟方法 'com.google.android.gms.tasks.Task com.google.firebase.auth.FirebaseAuth.createUserWithEmailAndPassword(java.lang .String, java.lang.String)' 在空对象引用上

标签: androidfirebaseflutterfirebase-authentication

解决方案


推荐阅读