I'm new to flutter and I'm working on an App that have multiple screens.
I would like to know to stop flutter from creating multiple screens of the same route, for example I have Page 1 and Page 2, if I click on the button to navigate to Page 2 and clicked again on the same button the application will push a new screen of Page 2 and i will have it twice and if I click on the return button it will send me back to the first created Page 2
is there a way to create every page only once and then reopen it if it's already pushed to the stack ?
I'm using Navigator.push
for all my navigation
These answers are not correct. PushReplacement
will still create a new instance of the widget. That's very simple to identify if you have a scrollable list in RouteA
and scroll it before navigating to a RouteB
. When you pushReplacement(RouteA)
, you'll see the scrolling position have changed to its initial state. That is because a new widget was instantiated, and that is not the behaviour you want.
You should use popUntil
, as previously answered by JoaoSoares
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With