Home > Blockchain >  Navigation in in flutter
Navigation in in flutter

Time:08-05

I have a request from a client who wants to skip one page in opening under some conditions and immediately open another page. However the problem is that when it goes back it wants to always show 2 pages. So page 1 opens page 3 and when I go back from page 3 it goes to page 2 and then station 1. I'm new to flutter and I don't know how to do it.

CodePudding user response:

Use pushReplacement for such Navigation

// In Screen 1
Navigator.pushReplacement(context, Screen3()) // Or Screen2()

// In Screen 3
Navigator.pushReplacement(context, Screen2())

// In Screen 2
Navigator.pushReplacement(context, Screen1())

CodePudding user response:

From page 1 to page 3 your can use

  Navigator.push(
    context,
    MaterialPageRoute(builder: (context) => const Page3()),

Then if you want to go to Page 2 from page 3 use WillPopScope in page 3

return WillPopScope(
  onWillPop: (){},
  child: Scaffold(
    body: Column(
      children: [],
    ),
  ),
);

Add the above code in page 3. Add condition to check if it should go to Page 1 or 2 in onWillPop and again use navigator.pop or navigator.pushReplacement

  • Related