【问题标题】:Flutter Navigation showing route as /Flutter Navigation 将路线显示为 /
【发布时间】:2020-02-13 06:24:13
【问题描述】:

我有一张带有 PopupMenuButton 的卡片,我可以点击它来执行“复制”操作。我也可以从卡详细信息页面执行相同的操作。我遇到的问题是返回主页,我必须同时满足两条路径。所以如果是从详情页执行的动作,我需要弹两次才能回到首页。

来自主页的操作:

首页 > 添加卡片页面

  • navigator.pop() 带我回到主页

详情页面的操作:

首页 > 卡片详情页面 > 添加卡片页面

  • 不得不在这里弹出两次。

我知道我必须至少执行一次pop,然后我使用popUntil 检查路线的当前状态。由于某种原因,它总是弹出两次。

调试后显示当前路由为/

  void _changeRoute(String newRouteName) {
    bool isNewRoute = false;

    // Pop once
    Navigator.pop(context); // after this I should be on home page for the first path

    Navigator.popUntil(context, (route) {
      print('Current route is ${route.settings.name}');

      if (route.settings.name == newRouteName) { // but this is showing current route as /
        isNewRoute = true;
      }
      return true;
    });

    print('is home page: $isNewRoute');

    if (!isNewRoute) {
      Navigator.pop(context);
    }
  }

【问题讨论】:

    标签: flutter dart navigator flutter-navigation


    【解决方案1】:

    我有这个工作。

    我的问题是在我的主应用程序中,我在 MaterialApp 上指定了 home 属性。根据文档,如果指定了home 属性,它将采用路由/。所以我的主页是/,我在我的路线中将它定义为/home,这被/覆盖了。

    【讨论】:

      猜你喜欢
      • 2019-04-11
      • 1970-01-01
      • 2022-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-04
      相关资源
      最近更新 更多