如何在颤动中弹出到特定屏幕

Roh*_*yan 8 uinavigationcontroller ios dart swift flutter

我推了四屏 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)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

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

请给出解决方案,谢谢

Sha*_*ain 16

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

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

您需要定义相同的路由名称

Navigator.of(context).popUntil((route){
  return route.settings.name == 'SecondPage';
}); 
Run Code Online (Sandbox Code Playgroud)