Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pop to specific screen in flutter

I pushed four screens ScreenOne >> ScreenTwo >> ScreenThree >> ScreenFour

and I'm at ScreenFour now I want to pop back to ScreenTwo

In Swift it works like this::

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

how i perform this operation in flutter.

Please give a solution, Thank you.

like image 312
Raj Aryan Avatar asked Dec 06 '19 12:12

Raj Aryan


People also ask

How do I navigate half screen in Flutter?

You can use the Navigator widget to provide any number of individual navigators in your app. Each Navigator will maintain it's own navigation stack. For example, if you wanted to split your app vertically with each half having it's own navigation stack: Column( children: <Widget>[ Navigator(...), Navigator(...) ] )

Can you pop scope in Flutter?

What is the WillPopScope widget? The WillPopScope widget comes with the Flutter framework. It gives us control over the back button action, allowing the current page to go back to the previous one if it meets certain requirements. This is achieved using a callback, which the widget takes in as one of its parameters.


1 Answers

If you didn't define any route in the MaterialApp then you need to define at the time of push.

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

You need to define the same route name

Navigator.of(context).popUntil((route){
  return route.settings.name == 'SecondPage';
}); 
like image 196
Shakti S.P. Swain Avatar answered Sep 18 '22 03:09

Shakti S.P. Swain