在flutter 路由跳转中,我们想要回到特定的一个页面
比如:从 A -> B-> C ->D,我们向从 D页面 pop至 B 页面。我们能够运用 popUtil办法回到 B 页面。

Navigator.popUnitil(context, ModalRoute.withName('/B'))

或许运用

   Navigator.popUntil(ctx.context, (route){
        if (route.settings.name == "/B"){
          return true;
        }else {
          return false;
        }
      });

但是 运转结果是 : 黑屏。

我们对 route.setting 进行打印后,发现 route.setting == null只要最后 一个A页面的route.setting有值,其name == '/'

所以,我们在跳转至B页面的时分,需要给B页面的routeSetting进行赋值

  Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) =>BPage(),
        settings: RouteSettings(name: '/B'),
      ));

这样就能够回到B页面了

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。