android - 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)' 在空对象引用上
解决方案
推荐阅读
- python - 如何找到已从客户端使用的域以在 python 套接字中到达我的服务器?
- javascript - 在字符串中查找查询匹配项
- python - 考虑到所需的休假,我如何使用 or-tools 安排员工轮班?
- docker - 重复的 RazorLanguageVersionAttribute 构建容器
- python - 连接外显子序列并在其间插入 Ns
- python - 无法在 Linux 上使用 pip 安装 Ropper
- html - 屏幕阅读器可读取切换内容中的列表信息
- upload - 尝试上传反混淆文件时出现错误
- python - 在 Python 中的 List 中查找和添加整数的最快方法
- php - 使用条件向我的数组添加一个新元素