【问题标题】:Get.to(MyPage()) - How to remove all previous routes - Flutter GetXGet.to(MyPage()) - 如何删除所有以前的路由 - Flutter GetX
【发布时间】:2021-01-31 09:15:33
【问题描述】:

我有一个简单的 Flutter 应用,我想删除所有以前的路由,但我想使用 GetX,怎么做?

现在可以使用了

Navigator.of(context).pushNamedAndRemoveUntil('/home', (Route<dynamic> route) => false);

但我想知道Get.to 或类似的正确方法

【问题讨论】:

    标签: flutter dart flutter-routes flutter-getx


    【解决方案1】:

    您正在寻找Get.reset();。请检查此page

     /// Clears all registered instances (and/or tags).
     /// Even the persistent ones.
     ///
     /// - [clearFactory] clears the callbacks registered by [Get.lazyPut()]
     /// - [clearRouteBindings] clears Instances associated with Routes when using
     ///   [GetMaterialApp].
     bool reset({bool clearFactory = true, bool clearRouteBindings = true}) =>
      GetInstance().reset(
          clearFactory: clearFactory, clearRouteBindings: clearRouteBindings);
    

    【讨论】:

      【解决方案2】:
      Get.offAll(Home());
      

      与命名路由:

      Get.offAllNamed('/home');
      

      有关文档的更多信息: https://github.com/jonataslaw/getx/blob/master/documentation/en_US/route_management.md

      【讨论】:

        【解决方案3】:

        如果要删除最后一页,请使用它。

        Get.off(Home());
        

        如果要删除所有以前的页面,请使用它。

        Get.offAll(Home());
        

        很简单

        【讨论】:

          【解决方案4】:

          使用Get.reset()这将删除所有以前的路线

          【讨论】:

            【解决方案5】:

            试试这个:

             Get.offNamedUntil('home', (route) => false);
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 2021-02-17
              • 2022-12-04
              • 2018-02-03
              • 1970-01-01
              • 2022-10-07
              • 2015-04-09
              • 2021-03-04
              • 2022-01-10
              相关资源
              最近更新 更多