I am trying to navigate back to a previous screen from my current screen.
OnWillPop
was deprecated thus I am using PopScope
with the following code
canPop: true,
onPopInvoked: (didPop)
{
Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder:(context)=>
StepperScreen(param1: widget.param1, param2: widget.param2)),(Route<dynamic>route)=>false);
},
child: Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(.... ```
On the back button for the IOS it works perfectly but not on the PopScope
``` Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder:(context)=>
StepperScreen(param1: widget.param1, param2: widget.param2)),(Route<dynamic>route)=>false); ```
Is there something I miss or should I use a different routing call.
I get the following response from the editor
``` I/ViewRootImpl@1beec50[MainActivity](28298): ViewPostIme key 0
I/ViewRootImpl@1beec50[MainActivity](28298): ViewPostIme key 1
D/Activity(28298): onKeyDown(KEYCODE_BACK)
D/Activity(28298): onKeyUp(KEYCODE_BACK) isTracking()=true isCanceled()=false hasCallback=false ```
Then the entire apps back navigation is broken and not even the back button in the app bar wants to work
2
Answers
Here is an example of how to implement PopScope:
With this example we open a dialog before poping, but you can do whatever else you want.
Naturally in this example, in he _showDialog method, a pop is done for really poping when the user validate the dialog.