Let say i have three screens: wallet
, payments
, add card
. I want to pop payments
screen from stack when i'm on add card
screen and navigate it to wallet
screen without using navigator.push
on click on icon plus the back icon of device.
Please help how to do this.
CodePudding user response:
It's not very clear from your question how your navigation stack should look: Is payments
first in the stack, and can you go from there to add card
and wallet
? Or should only one exist?
I think you can use pushReplacement
: https://api.flutter.dev/flutter/widgets/Navigator/pushReplacement.html
That way, it'll automatically replace the current route with the new one, and your back button will simply close the app (or go back to the screen before it). If you want some custom behavior when the back button is pressed, you can always use a WillPopScope
: https://api.flutter.dev/flutter/widgets/WillPopScope-class.html
CodePudding user response:
try this:
Navigator.pushReplacement()
CodePudding user response:
Navigator.removeRoute(context, MaterialPageRoute(builder: (context) => payments()));
use this code when you remove your payments screen