Flutter lifecycle suspending method not getting called
You should try the didPopRoute() lifecycle hook for back button on Android. From the docs:
Called when the system tells the app to pop the current route. For example, on Android, this is called when the user presses the back button.
class _HomePageState extends State<HomePage> with WidgetsBindingObserver { WidgetsBinding binding = WidgetsBinding.instance; @override Future<bool> didPopRoute() { // Android user pressed back button final bool preventAppFromClosing = true; return preventAppFromClosing; } @override void initState() { super.initState(); binding.addObserver(this); } @override void dispose() { binding.removeObserver(this); super.dispose(); }}