为什么我的更新电子邮件不起作用,Firebase和Flatter?
我想在firebase中构建一个更新用户电子邮件的功能,所以我就是这么做的: 1-检查是否有互联网。 2-使用我在注册中上载firestore后从firestore收到的电子邮件执行user.updateEmail,它不能为空,因为我已将其用完,并且它还打印了错误:为什么我的更新电子邮件不起作用,Firebase和Flatter?,firebase,flutter,firebase-authentication,Firebase,Flutter,Firebase Authentication,我想在firebase中构建一个更新用户电子邮件的功能,所以我就是这么做的: 1-检查是否有互联网。 2-使用我在注册中上载firestore后从firestore收到的电子邮件执行user.updateEmail,它不能为空,因为我已将其用完,并且它还打印了错误: NoSuchMethodError: The method 'updateEmail' was called on null. I/flutter ( 9769): Receiver: null I/flutter ( 9769):
NoSuchMethodError: The method 'updateEmail' was called on null.
I/flutter ( 9769): Receiver: null
I/flutter ( 9769): Tried calling: updateEmail("omarkaram1st@gmail.com")
看到它收到了电子邮件,但不知何故它无法发送电子邮件;
代码:
在调用
user.updateEmail(电子邮件)
时,user
似乎为空。我们无法说明这是由于您共享的代码造成的,但防止错误的快速方法是在调用wait\u auth.currentUser()
后检查null
你能添加一个代码片段来更好地理解你的场景吗?很抱歉,忘了这么做。XDI按照你说的做了,但它没有检测到用户是否为空。在这种情况下,错误消息来自其他地方。您可能希望在调试器中运行代码,然后跳过
user.updateEmail(email)
调用,查看这是否是失败的。
switchAccount() async {
try {
final user = await _auth.currentUser();
final result = await InternetAddress.lookup('google.com');
try {
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
user.updateEmail(email);
AwesomeDialog(
btnOkText: 'Ok',
context: context,
headerAnimationLoop: false,
dialogType: DialogType.INFO,
animType: AnimType.BOTTOMSLIDE,
title: 'Info',
desc: 'A Reset Email Has Been Sent To $email',
btnOkOnPress: () {},
)..show();
}
} catch (e) {
print(e);
}
} on SocketException catch (_) {
AwesomeDialog(
btnOkText: 'Retry',
context: context,
headerAnimationLoop: false,
dialogType: DialogType.ERROR,
animType: AnimType.BOTTOMSLIDE,
title: 'Error',
desc:
'Make Sure That You Have an Internet Connection Before Pressing Retry',
btnOkOnPress: () =>
Navigator.pushReplacementNamed(context, '/HomePage'),
)..show();
}
}
final user = await _auth.currentUser();
if (user != null) {
final result = await InternetAddress.lookup('google.com');
try {
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
user.updateEmail(email);
...
}
} catch (e) {
print(e);
}
}
else {
... do something relevant when no user is signed in
}