如何在flutter中发送一封验证电子邮件()

发布于 2025-01-24 04:04:37 字数 1492 浏览 0 评论 0原文

当用户单击“注册”按钮时,我不会发送电子邮件验证。到目前为止,我的注册代码发送了电子邮件验证,但用户无法导航到下一页(CignularProgressIndicator继续加载),

这是我的代码

   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;
                    });
                  
                }}

I wan't when a user clicks sign up button an email verification is sent. 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)

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;
                    });
                  
                }}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丶视觉 2025-01-31 04:04:37

sendemailverification()返回future< void> so emailsent不会设置。您应该等待 中的验证调用尝试...捕获以处理响应。

更像这样:

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
  }
}

sendEmailVerification() returns a Future<void> so EmailSent is not going to get set. You should await the verification call in a try...catch to handle the response.

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
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文