颤振:移至新屏幕而无后退 [英] Flutter: Move to a new screen without back

查看:132
本文介绍了颤振:移至新屏幕而无后退的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Flutter应用中实现身份验证流程.

I'm implementing an authentication flow in my Flutter app.

尝试登录后,将使用以下代码打开CheckAuth (检查用户是否已登录,然后相应地打开主屏幕或注册屏幕):

After a sign in attempt, the CheckAuth (which checks whether a user is signed in or not and then opens home screen or sign up screen accordingly) is opened with this code:

  void _signIn() async {
    await _auth
        .signInWithEmailAndPassword(
            email: _userEmail.trim(), password: _userPassword.trim())
        .then((task) {
      // go to home screen
      if (task.getIdToken() != null) {
        setState(() {
          Navigator.pushReplacement(
              context,
              new MaterialPageRoute(
                  builder: (BuildContext context) => new CheckAuth()));
        });
      } else {
        print("Authentication failed");
      }
    });
  }

问题:我可以成功登录该应用程序,但是如果我在登录后点击后退"按钮,它将返回到登录屏幕(但我希望它会从该应用程序退出).

Problem: I can successfully sign in to the app, but if I tap back button after I sign in, it goes back to the sign in screen (while I expect it to exit from the app).

问题:如何在Flutter中从一个屏幕移动到另一个屏幕而又没有回头路?

我需要以某种方式删除导航器历史记录吗?还是根本不使用导航器?我尝试了 Navigator.replace 方法,但似乎没有用.

Do I need to somehow delete the navigator history? Or don't use navigator at all? I tried Navigator.replace method, but it didn't seem to work.

推荐答案

离开身份验证屏幕时,您也需要使用Navigator.pushReplacement.不仅是重定向到登录页面时.

You need to use Navigator.pushReplacement when leaving the auth screen too. Not just when redirecting to login page.

这篇关于颤振:移至新屏幕而无后退的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆