You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
FlutterFragmentActivity support for predictive back #149753
Several popular pub packages (local_auth, health) require the use of FlutterFragmentActivity in apps. Apps that use those packages should be able to support predictive back, too.
The package flutter_stripe also requires FlutterFragmentActivity. So I'm stuck with Flutter v3.22.3. Our project is totally crappy without back gesture since the "Stable" version of Flutter v3.24.1. 😥
I understand that you must be very busy, but do you have an ETA for an update? 😅
If I try to just change FlutterActivity to FlutterFragmentActivity in MainActivity.kt it seems to be working, am I missing something? Predictive back works when leaving the app from the root route. PredictiveBackPageTransition doesn't work, but it correctly defaults to ZoomPageTransition and back gestures work.
classMainActivity: FlutterFragmentActivity() {
}
@NeKoFu what is your setup like? Can you try on the master branch?
@justinmc I'm using go_router for navigation, and since the flutter_stripe package requires FlutterFragmentActivity, I had to switch to that. With Flutter 3.22.3, the back gesture worked as expected, returning to the previous page. However, after upgrading to Flutter 3.24.1 (stable channel), the back gesture now closes the app instead of navigating back.
@justinmc To isolate the issue, I had created, like you, a minimal project with navigation between two pages using go_router. And indeed, good news, this minimal project is working again using the master branch and your commits related to FlutterFragmentActivity. 😊
However, 😥 I was still facing the problem on my actual application project. So, I took some time to investigate, and what I found is that if a function is attached to the onNavigationNotification attribute in MaterialApp.router(), then the Back Gesture consistently closes the application. 🤔
import'package:flutter/material.dart';
import'package:navtest/route.dart';
voidmain() {
runApp(constMyApp());
}
classMyAppextendsStatelessWidget {
constMyApp({super.key});
@overrideWidgetbuild(BuildContext context) {
returnMaterialApp.router(
title:'Flutter Demo',
theme:ThemeData(
colorScheme:ColorScheme.fromSeed(seedColor:Colors.deepPurple),
useMaterial3:true,
),
routerConfig:AppRoutes.router,
// onNavigationNotification: (NavigationNotification notification) => true, // <<-- break the fix and close the app on back gesture
);
}
}
@darshankawar@justinmc Any chance this can be bumped to P1? Entire app navigation seems to be really broken in many ways for apps using FlutterFragmentActivity (which is also unavoidable for many projects) and disabling predictive back on android manifest doesn't seem to fix it anymore starting with flutter 3.24. Both PopScope and the old WillPopScope don't work as intended at all.
Reacted by Philipp Bauer, Bryan, Francisco Venegas Aguilera, Muhammed Basil E, Ercan Tomac, kevinhuijsman13 and praiaCaioCoelho
Thanks for everyone providing context here. I'm trying to find the bandwidth for this and will post back. If anyone else wants to submit a PR, I'll assign myself if I start working on this, otherwise it's free for anyone to work on it.
Reacted by 京华 and Kgym-Hina
Reacted by Francisco Venegas Aguilera, Muhammed Basil E and Kgym-Hina
Steps to reproduce
1- Run the project
2- Switch the tab using the bottom navigation bar
3- go to the inner page
4 - press the back button (will redirect to the home page),
5 - press the back button once more (the app will close)
expected result
As per the code , on the step 5 app should go to the 1st tab in the bottom navigation bar , again pressing back button from there should show a confirmation dialogue
[√] Flutter (Channel stable, 3.24.4, on Microsoft Windows [Version 10.0.26100.2454], locale en-US)
• Flutter version 3.24.4 on channel stable at C:\Flutter\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 603104015d (5 weeks ago), 2024-10-24 08:01:25 -0700
• Engine revision db49896cf2
• Dart version 3.5.4
• DevTools version 2.37.3
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
• Android SDK at C:\Users\***\AppData\Local\Android\sdk
• Platform android-35, build-tools 35.0.0
• Java binary at: C:\Users\***\.jdks\corretto-17.0.13\bin\java
• Java version OpenJDK Runtime Environment Corretto-17.0.13.11.1 (build 17.0.13+11-LTS)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.11.5)
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.11.35327.3
• Windows 10 SDK version 10.0.22621.0
[√] Android Studio (version 2024.2)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)
[√] IntelliJ IDEA Community Edition (version 2024.2)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2024.2.4
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
[√] VS Code (version 1.95.3)
• VS Code at C:\Users\***\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.100.0
[√] Connected device (4 available)
• sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 15 (API 35) (emulator)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.26100.2454]
• Chrome (web) • chrome • web-javascript • Google Chrome 131.0.6778.86
• Edge (web) • edge • web-javascript • Microsoft Edge 130.0.2849.80
[√] Network resources
• All expected network resources are available.
• No issues found!
[√] Flutter (Channel stable, 3.24.4, on Microsoft Windows [Version 10.0.26100.2454], locale en-US)
• Flutter version 3.24.4 on channel stable at C:\Flutter\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 603104015d (5 weeks ago), 2024-10-24 08:01:25 -0700
• Engine revision db49896cf2
• Dart version 3.5.4
• DevTools version 2.37.3
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
• Android SDK at C:\Users\***\AppData\Local\Android\sdk
• Platform android-35, build-tools 35.0.0
• Java binary at: C:\Users\***\.jdks\corretto-17.0.13\bin\java
• Java version OpenJDK Runtime Environment Corretto-17.0.13.11.1 (build 17.0.13+11-LTS)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.11.5)
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.11.35327.3
• Windows 10 SDK version 10.0.22621.0
[√] Android Studio (version 2024.2)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)
[√] IntelliJ IDEA Community Edition (version 2024.2)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2024.2.4
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
[√] VS Code (version 1.95.3)
• VS Code at C:\Users\***\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.100.0
[√] Connected device (4 available)
• sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 15 (API 35) (emulator)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.26100.2454]
• Chrome (web) • chrome • web-javascript • Google Chrome 131.0.6778.86
• Edge (web) • edge • web-javascript • Microsoft Edge 130.0.2849.80
[√] Network resources
• All expected network resources are available.
• No issues found!
Hi @ZhuJHua, sorry but I don't use Getx...do you have any ideas? I have to use FlutterFragmentActivity for local_auth, but after changing from FlutterActivity i have a problem cannot back (using system back button) to previous page and app will minimize after click system back button. I think you have same problem but unlucky i cannot fixing with this solution (Milad-Akarie/auto_route_library#2059 (comment)) to my project.
Any updates on this? Proper support for FlutterFragmentActivity is very important since important features like biometrics login cannot work without it.
Reacted by Philipp Bauer, Alexandru Dochioiu, mihiro-zenplace, Guillaume Damiens, Cenk YAĞMUR, Anil chauhan, Michael, 京华, Andrey Ilychev, Kamil Kras and 5 more
I am not entirely sure, if I do completly understand this issue. However the problems previously experienced with back button handling in a FlutterFragementActivity after upgrading to Flutter 3.22 seem to be resolved with the release of Flutter 3.32 (probably by #161545).
I am not entirely sure, if I do completly understand this issue. However the problems previously experienced with back button handling in a FlutterFragementActivity after upgrading to Flutter 3.22 seem to be resolved with the release of Flutter 3.32 (probably by #161545).
I'm using auto_route, predictive back gesture on my main screen well work using3.32 but not the others (created by .push). Does your routes works ?
I am not entirely sure, if I do completly understand this issue. However the problems previously experienced with back button handling in a FlutterFragementActivity after upgrading to Flutter 3.22 seem to be resolved with the release of Flutter 3.32 (probably by #161545).
This remains an issue as of Flutter 3.35.7.
It works when exiting the app, but internal page transitions are not using Predictive Back. Unfortunately libraries like RevenueCat require FlutterFragementActivity, so I cannot switch.
I use this approach. Navigation seems fine with it
final materialApp =MaterialApp(
// FLUTTER 3.24.x and newer (when using FlutterFragmentActivity)// android navigation bugs due to predictive back gesture// https://github.com/flutter/flutter/issues/149753// https://github.com/Milad-Akarie/auto_route_library/issues/1788// https://github.com/flutter/flutter/issues/145290// https://github.com/flutter/flutter/issues/138614#issuecomment-1909155402// https://github.com/flutter/flutter/issues/145159// https://github.com/flutter/flutter/issues/138737// https://github.com/flutter/flutter/issues/155441//// Note, we cannot get rid of FlutterFragmentActivity because it is required for local auth to work
onNavigationNotification:UniversalPlatform.isAndroid
? (notification) {
switch (WidgetsBinding.instance.lifecycleState) {
casenull:caseAppLifecycleState.detached:caseAppLifecycleState.inactive:// Avoid updating the engine when the app isn't ready.returntrue;
caseAppLifecycleState.resumed:caseAppLifecycleState.hidden:caseAppLifecycleState.paused:SystemNavigator.setFrameworkHandlesBack(true);
/// This must be `true` instead of `notification.canHandlePop`, otherwise application closes on back gesture.returntrue;
}
}
:null,
@anders-au Those changes are meant to properly disable predictive gestures (I think also in android manifest you'd need to do it) because it breaks app navigation in flutter.
To my knowledge, you cannot possibly use predictive gestures with FlutterFragementActivity without breaking the navigation.
Your only choice are:
Use FlutterFragementActivity and fully disable predictive gestures
Use FlutterActivity to be able to keep predictive gestures, but ofc this is not possible with some libraries.
I never found any workaround to use FlutterFragementActivity with predictive gestures.
Reacted by Guilherme Nascimento, 京华, Thiha, tyler401go, Thea Choem, Levin and paigu
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
roberto-gigli commentedon Jun 7, 2024
I'm experiencing the same issue, and can't add predictive back if i use local auth in my projects
NeKoFu commentedon Sep 3, 2024
The package flutter_stripe also requires FlutterFragmentActivity. So I'm stuck with Flutter v3.22.3. Our project is totally crappy without back gesture since the "Stable" version of Flutter v3.24.1. 😥
I understand that you must be very busy, but do you have an ETA for an update? 😅
justinmc commentedon Sep 3, 2024
If I try to just change FlutterActivity to FlutterFragmentActivity in MainActivity.kt it seems to be working, am I missing something? Predictive back works when leaving the app from the root route. PredictiveBackPageTransition doesn't work, but it correctly defaults to ZoomPageTransition and back gestures work.
@NeKoFu what is your setup like? Can you try on the master branch?
Maybe I did enable this in FlutterFragmentActivity here? https://github.com/flutter/engine/pull/52302/files#diff-893547c230a70f1b0618f0b79a56c67d8506f0983a5a92b819f13c1071fd7d84
Example app that I used, just navigation nothing fancy
NeKoFu commentedon Sep 4, 2024
@justinmc I'm using
go_routerfor navigation, and since theflutter_stripepackage requires FlutterFragmentActivity, I had to switch to that. WithFlutter 3.22.3, the back gesture worked as expected, returning to the previous page. However, after upgrading toFlutter 3.24.1(stable channel), the back gesture now closes the app instead of navigating back.I will try with the master branch tomorrow 😉
NeKoFu commentedon Sep 8, 2024
@justinmc To isolate the issue, I had created, like you, a minimal project with navigation between two pages using
go_router. And indeed, good news, this minimal project is working again using the master branch and your commits related to FlutterFragmentActivity. 😊However, 😥 I was still facing the problem on my actual application project. So, I took some time to investigate, and what I found is that if a function is attached to the
onNavigationNotificationattribute inMaterialApp.router(), then the Back Gesture consistently closes the application. 🤔AlexDochioiu commentedon Oct 20, 2024
@darshankawar @justinmc Any chance this can be bumped to P1? Entire app navigation seems to be really broken in many ways for apps using FlutterFragmentActivity (which is also unavoidable for many projects) and disabling predictive back on android manifest doesn't seem to fix it anymore starting with flutter 3.24. Both PopScope and the old WillPopScope don't work as intended at all.
justinmc commentedon Oct 22, 2024
Thanks for everyone providing context here. I'm trying to find the bandwidth for this and will post back. If anyone else wants to submit a PR, I'll assign myself if I start working on this, otherwise it's free for anyone to work on it.
AlexDochioiu commentedon Oct 29, 2024
For anyone having the same issue, this workaround fixes navigation the navigation for Flutter 3.24.x : Milad-Akarie/auto_route_library#2059 (comment)
bazl-E commentedon Nov 5, 2024
sample project to reproduce the issue https://github.com/safaIocod/iso_sample
Steps to reproduce
1- Run the project
2- Switch the tab using the bottom navigation bar
3- go to the inner page
4 - press the back button (will redirect to the home page),
5 - press the back button once more (the app will close)
expected result
As per the code , on the step 5 app should go to the 1st tab in the bottom navigation bar , again pressing back button from there should show a confirmation dialogue
backids99 commentedon Dec 1, 2024
Hi @AlexDochioiu, after i trying your reference but still not working for me. I try routing using https://docs.flutter.dev/cookbook/navigation/named-routes not working, and i try using other way https://pub.dev/packages/go_router still not working to using system navigation back for pop route.
flutter doctor:
ZhuJHua commentedon Dec 1, 2024
Did you use the Getx as route manager?
backids99 commentedon Dec 1, 2024
Hi @ZhuJHua, sorry but I don't use Getx...do you have any ideas? I have to use FlutterFragmentActivity for local_auth, but after changing from FlutterActivity i have a problem cannot back (using system back button) to previous page and app will minimize after click system back button. I think you have same problem but unlucky i cannot fixing with this solution (Milad-Akarie/auto_route_library#2059 (comment)) to my project.
4 remaining items
AlexDochioiu commentedon Jan 10, 2025
Any updates on this? Proper support for FlutterFragmentActivity is very important since important features like biometrics login cannot work without it.
kevinhuijsman13 commentedon Jan 16, 2025
Any updates on this?
FrankenApps commentedon May 25, 2025
I am not entirely sure, if I do completly understand this issue. However the problems previously experienced with back button handling in a
FlutterFragementActivityafter upgrading to Flutter 3.22 seem to be resolved with the release of Flutter 3.32 (probably by #161545).EArminjon commentedon May 25, 2025
I'm using auto_route, predictive back gesture on my main screen well work using3.32 but not the others (created by .push). Does your routes works ?
anders-au commentedon Nov 6, 2025
This remains an issue as of Flutter 3.35.7.
It works when exiting the app, but internal page transitions are not using Predictive Back. Unfortunately libraries like RevenueCat require FlutterFragementActivity, so I cannot switch.
Has anyone found a workaround for this?
AlexDochioiu commentedon Nov 6, 2025
I use this approach. Navigation seems fine with it
anders-au commentedon Nov 7, 2025
Thanks for this, but this did not work for me.
Are there any other steps that you had to apply to get this to work (aside from the pageTransitionsTheme and AndroidManifest code changes).
To confirm it wasn't something else in my config preventing it, I just switched back to FlutterActivity and predictive back worked.
(Just to clarify, I am talking about predictive back within the app, where you can see the previous screen mid-gesture.)
AlexDochioiu commentedon Nov 7, 2025
@anders-au Those changes are meant to properly disable predictive gestures (I think also in android manifest you'd need to do it) because it breaks app navigation in flutter.
To my knowledge, you cannot possibly use predictive gestures with
FlutterFragementActivitywithout breaking the navigation.Your only choice are:
FlutterFragementActivityand fully disable predictive gesturesFlutterActivityto be able to keep predictive gestures, but ofc this is not possible with some libraries.I never found any workaround to use
FlutterFragementActivitywith predictive gestures.[Android] Add predictive back support for FlutterFragment and Flutter…
[Android] Add predictive back support for FlutterFragment and Flutter…
[Android] Add predictive back support for FlutterFragment and Flutter…
github-actions commentedon Feb 16, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.[Android] Add predictive back support for FlutterFragment and Flutter…