我试图返回值在用户中,我得到这个错误,如果我试图通过添加null符号修复这个错误,它不会返回任何值,因为所有这些值将为null,我想返回这个值并保存它,这样我就可以使用它,什么可以是解决方案,请指导
FirebaseAuth auth = FirebaseAuth.instance;
User? user = FirebaseAuth.instance.currentUser;
CollectionReference users = FirebaseFirestore.instance.collection('users');
Future<void> addUser(context) {
//before we add user we need to check this user already signedin earlier using same number or not
//if signedIn before no need to add , because it may have added already. so just need to skip adduser
return users
.add({
'uid': user.uid,
'mobile': user.phoneNumber,
'email': user.email
})
.then((value){
//after add data to firebase then will go to next screen
//if you pushreplacementName or push replacement, then u cant go back to previous screen
Navigator.pushReplacementNamed(context, LocationScreen.id);
})
.catchError((error) => print("Failed to add user: $error"));
}
1条答案
按热度按时间u3r8eeie1#
这是因为uid可以为空。请尝试以下操作
如果uid为空,默认用户名将保存在firestore中。