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?
4
Try to use NavigatorObserver to monitor navigation events and implement custom back navigation behavior
Add navigatorObservers: [MyNavigatorObserver()]
to MaterialApp
class MyNavigatorObserver extends NavigatorObserver {
@override
void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
// Custom logic when a route is popped
print('Route popped');
}
}
Navigate to next page
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondPage()),
);
Navigate back with icon back button
Navigator.pop(context);
1