我正在尝试删除FirebaseUser,它返回空错误。我不知道我的代码有什么问题。
有人可以给出适当的解释来回答原因,因为我是这个错误的新手!
错误:
D/FirebaseAuth(16061): Notifying id token listeners about user ( r6Nn5Gxxxxxxxxxxxxxxx ).
I/flutter (16061): Deletion error NoSuchMethodError: The method '[]' was called on null.
I/flutter (16061): Receiver: null
I/flutter (16061): Tried calling: []("user")
这是我要删除用户的方式:
new FlatButton(
child: Text("Delete"),
onPressed: () async {
if (password.text.length == 0) {
showInSnackBar("Please enter your password");
} else {
FirebaseUser firebaseUser =
await FirebaseAuth.instance.currentUser();
String uid = firebaseUser.uid;
var credential = EmailAuthProvider.getCredential(
email: firebaseUser.email,
password: password.text);
var result = await firebaseUser
.reauthenticateWithCredential(credential);
try {
await result.user.delete();
} on PlatformException catch (e) {
print("///////// ${e.code}");
String errorCde = e.code;
if (errorCde == "ERROR_WRONG_PASSWORD") {
showInSnackBar("Wrong password! Please try agian.");
} else if (errorCde == "ERROR_TOO_MANY_REQUESTS") {
showInSnackBar(
"You've tried too many times, Please try again in a while!");
} else if (errorCde ==
"ERROR_NETWORK_REQUEST_FAILED") {
showInSnackBar(
"Please check your internet connection");
}
} catch (e) {
print("Deletion error $e");
showInSnackBar("Something went wrong");
}
}
},
),