[英]How to send a verification email on registerUsingEmailPassword() in flutter
I wan't when a user clicks sign up button an email verification is sent.我不想在用户单击注册按钮时发送 email 验证。 So far with my code on signup an email verification is sent but user can't navigate to the next page (CircularProgressIndicator keeps on loading)
到目前为止,我的注册代码已发送 email 验证,但用户无法导航到下一页(CircularProgressIndicator 不断加载)
Here is my code这是我的代码
onPressed: () async {
if (_regFormKey.currentState!.validate()) {
setState(() {
_isProcessing = true;
});
User? user = await FireAuth.registerUsingEmailPassword(
name: nameController,
email: _emailController.text,
password: _passwordController.text,
);
if (user != null) {
bool EmailSent = user.sendEmailVerification() as bool;
//I think something is wrong here
if (EmailSent) {
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(
builder: (context) => ProfilePage(user: user),
),
ModalRoute.withName('/'),
); }
} else{
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text(' Account exists or Network problems'),
backgroundColor: Colors.red,
));}
setState(() {
_isProcessing = false;
});
}}
sendEmailVerification()
returns a Future<void>
so EmailSent
is not going to get set. sendEmailVerification()
返回一个Future<void>
所以EmailSent
不会被设置。 You should await
the verification call in a try...catch
to handle the response.您应该在
try...catch
中await
验证调用以处理响应。
More like this:更像这样:
if (user != null) {
try {
await user.sendEmailVerification();
/// sent successfully
// TODO: put your navigation here
} catch (e) {
/// error sending verification
// TODO: show snackbar
// TODO: set _isProcessing to false
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.