I've been having a maddening issue with Flutter and GoRouter for a while now, When I press the phone's back button it either minimizes the app or closes it instead of popping to the previous page. It seems to only be an issue on Android 14 and pops perfectly on earlier Android versions
I'm Using PopScope to handle the pops Like I said, Popping works fine in-app and also when using older Android versions but it's not working with v14 when pressing the Android's own back button I'm currently experiencing this on my Samsung and also on an Android emulator using Android 14
I've seen similar posts but nothing exactly related to this issue
I humbly request the assistance of anybody who knows how to solve this please...And yes i have read the documentation
I've tried a bunch of changes in the GoRouter and even replaced PopScope with something else and asked on another form about it, I also looked into
https://docs.flutter.dev/release/breaking-changes/android-predictive-back
which didn't solve the issue either
Looked into similar issues on StackOverflow aswell
I don't think GoRouter's backButtonDispatcher is working well with Android 14
any thoughts?
My Router is setup as such
GoRouter router = GoRouter(
initialLocation: LoginScreen.routeName,
debugLogDiagnostics: true,
routes: <RouteBase>[
GoRoute(
path: LoginScreen.routeName,
name: LoginScreen.title,
pageBuilder: (context, state) => MaterialPage<void>(
key: state.pageKey,
child: const LoginScreen(),
),
),
GoRoute(
path: PinScreen.routeName,
name: PinScreen.title,
pageBuilder: (context, state) => MaterialPage<void>(
key: state.pageKey,
child: const PinScreen(),
),
),
And my main is setup like
return MaterialApp.router(
scaffoldMessengerKey: scaffoldMessengerKey,
title: 'My APP',
localizationsDelegates: const [
AppLocalizationsDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
locale: AppLocalizations.getStoredLocale(),
supportedLocales: const [
Locale('en'),
Locale('af'),
],
theme: ThemeData(brightness: Brightness.light, useMaterial3: false),
darkTheme: ThemeData(brightness: Brightness.dark, useMaterial3: false),
routerConfig: router,
);
Removing
android:enableOnBackInvokedCallback="true"
from the Android manifest fixes the issue.