【问题标题】:How can I pop to specific screen in flutter如何在颤动中弹出到特定屏幕
【发布时间】:2020-03-31 10:19:54
【问题描述】:

我推了四个屏幕 ScreenOne >> ScreenTwo >> ScreenThree >> ScreenFour

我现在在 ScreenFour,我想跳回 ScreenTwo

在 Swift 中它是这样工作的::

if let viewControllers: [UIViewController] = self.navigationController!.viewControllers {
    for vc in viewControllers
    {
        if (vc is SecondViewController)
        {
            self.navigationController!.popToViewController(vc, animated: true)
        }
    }
}

我如何在颤振中执行此操作。

请给出解决方案,谢谢

【问题讨论】:

标签: ios swift flutter dart uinavigationcontroller


【解决方案1】:

如果您没有在 MaterialApp 中定义任何路由,则需要在推送时定义。

Navigator.of(context).push(
    MaterialPageRoute(builder: (_) {
      return SecondPage();
    },
      settings: RouteSettings(name: 'SecondPage',),
    ));

需要定义相同的路由名称

Navigator.of(context).popUntil((route){
  return route.settings.name == 'SecondPage';
}); 

【讨论】:

    【解决方案2】:

    我相信那是 Navigator.popUntil 方法。

    您需要在您的 materialApp 中定义您的路线,以便 Navigator 识别它。为了使下面的代码正常工作,需要在我的 MaterialApp 中定义“/home”。

    Navigator.popUntil(context, ModalRoute.withName('/home'));
    

    【讨论】:

      【解决方案3】:

      试试pushNamedAndRemoveUntil

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

      如需深入阅读,请关注this

      【讨论】:

        【解决方案4】:

        如果您不想使用命名路由,那么只需使用-- pushAndRemoveUntil

        例子--

        Navigator.pushAndRemoveUntil(context, MaterialPageRoute(
                                  builder: (context) => MyHomePage()), (route) => false);
        

        【讨论】:

          猜你喜欢
          • 2021-11-25
          • 2021-12-27
          • 1970-01-01
          • 2021-03-28
          • 2020-10-29
          • 1970-01-01
          • 2023-01-11
          • 2021-11-02
          • 1970-01-01
          相关资源
          最近更新 更多