【问题标题】:Navigator routes Clear the stack of flutterNavigator routes 清除flutter的堆栈
【发布时间】:2023-03-27 17:46:01
【问题描述】:

在我的应用程序中,我有三个屏幕登录、verifyotp、generatepass。我知道如何从一页移动到另一页,例如:Navigator.pushNamed(context, "/theNameOfThePage");。 我有一个流程,我从 login->verifyotp->generatepass 移动我的问题现在是如何从 generatepass 移动到登录页面并清除所有堆栈。 我是一名 android 开发人员,所以在 android 中我们有 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);。 我怎样才能在颤振中达到相同的结果!

【问题讨论】:

    标签: dart flutter


    【解决方案1】:

    彻底清除 Navigator 的历史并导航到新路线:

    void _logout() {
       Navigator.pushNamedAndRemoveUntil(context, "/newRouteName", (r) => false);
    }
    

    【讨论】:

      【解决方案2】:

      使用Navigator.popUntil

      void _logout() {
        Navigator.popUntil(context, ModalRoute.withName('/login'));
      }
      

      【讨论】:

      • Navigator.popUntil(context, ModalRoute.withName('/')); 为我工作!我的登录页面有routes: <String, WidgetBuilder>{ "/VerifyOtp": (BuildContext context) => new VerifyOtp(), "/GeneratePass": (BuildContext context) => new GeneratePass(), },
      【解决方案3】:

      要添加到Paul Iluhin's answer above,如果要向新页面传递参数,只需在(r) => false 后面添加参数即可。这是一个例子。

      Navigator.pushNamedAndRemoveUntil(context, "/newRouteName", (r) => false, arguments: {
        "arg_1": firstArgument,
        "arg_2": secondArgument
      });
      

      【讨论】:

      • 谢谢亲爱的,感谢您的回答,它有效:)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-26
      • 2021-02-12
      • 1970-01-01
      • 2021-10-11
      • 2011-09-19
      • 2011-08-07
      • 1970-01-01
      相关资源
      最近更新 更多