The device back button is closing the application. But the application back button is working. ie,
Navigator.pop(context);
Any pointers to fix this issue?
The device back button is closing the application. But the application back button is working. ie,
Navigator.pop(context);
Any pointers to fix this issue?
2
Answers
To prevent your Flutter app from closing when the device back button is pressed and instead ensure it behaves like your app’s back button (Navigator.pop(context)), you can use the WillPopScope widget. This widget intercepts the back button press, allowing you to control the behavior.
presses.
pressed. Returning false prevents the default behavior (which would
close the app), while Navigator.pop(context) manually navigates back
in the app’s navigation stack.
Try to use NavigatorObserver to monitor navigation events and implement custom back navigation behavior
Add
navigatorObservers: [MyNavigatorObserver()]
toMaterialApp
Navigate to next page
Navigate back with icon back button