-
Notifications
You must be signed in to change notification settings - Fork 26.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Predictive back gesture Android #132504
Comments
Just wanted to point out that a lot of people are going to run into this issue, since adb is already warning: W/OnBackInvokedCallback(13376): OnBackInvokedCallback is not enabled for the application.
W/OnBackInvokedCallback(13376): Set 'android:enableOnBackInvokedCallback="true"' in the application manifest. However, if you set this value, Flutter is never even passed traditional back button push events. I set this value, following the directions in the logs, and then promptly forgot about it. A couple of weeks later realized that the back button had stopped working in my app. It took me a whole week to track down why Flutter wasn't even receiving back button events. |
@lukehutch Thanks for pointing this out for anyone else with this problem. Can I ask how exactly you reproduce it? What version of Flutter were you using? If I just create a new Flutter app, set |
@justinmc I'm on Flutter 3.13.9 (Android emulator, API 33). Tested again just now. If I add I debugged this all the way down to the method channel in Flutter, and the Back events are simply never received by Flutter. One twist though is that if you push the Back button with this attribute added, then the app is popped when the Back button is pressed (i.e. Back returns to the home screen). In other words, it's not like the Back button does nothing at all, but it consistently closes the app. So the Android app generated by Flutter is probably still receiving the Back button, but it just doesn't do anything with it. What this means though is that proper Back button behavior can't be implemented in Flutter, e.g. by means of a /// Make back button close any open dialogs first, and only pop the route
/// if there are no dialogs open. (Default behavior is to pop the app on
/// every back button press)
class FixedBackButtonDispatcher extends RootBackButtonDispatcher {
@override
Future<bool> didPopRoute() async {
// Close any open modal dialog before attempting to pop route
if (navigatorKey.currentState?.canPop() ?? false) {
navigatorKey.currentState!.pop();
return true;
}
// Pop route, or pop app if at top level
return super.didPopRoute();
}
} Incidentally, this is a separate issue, but it would be nice if the above |
Noticed this issue as well. What is the proper way for implementing As mentioned, it currently breaks the back button on android (minimizes the app instead of popping the route in my case). |
@justinmc I can confirm that the issue is fixed on the current Flutter beta channel. Thanks! |
when will this come to Stable ..? |
Status updateThere are two main parts to this issue, 1. when navigating out of a Flutter app and 2. when navigating within a Flutter app. 1. Navigating out of the appCompleted in #132249 and currently on stable (see f68d03f). 2. Navigating within the appIn progress. Tracked in #131961. Engine PR: flutter/engine#49093 Framework PR: #141373 |
All of the minimum PRs for this have been merged, so I'm closing this as completed. There will be follow-up work on OpenContainer transitions (flutter/packages#6321) and making it easier to write custom predictive back transitions, but I'll track those in their own PRs. |
Let me give a full update on the state of predictive back right now. Inter-app and intra-app predictive back are now supported by Flutter
Setting up your app to support predictive backCurrently (Android API 34) predictive back is not even supported natively without jumping through some hoops. See the guide for how to get your Flutter app and device set up, including the part about migrating to PopScope if needed. In addition, be sure you're on 3.21.0-16.0.pre or above, and you'll need to opt-in to using the new route transitions for now like this: return MaterialApp(
theme: ThemeData(
brightness: Brightness.light,
pageTransitionsTheme: const PageTransitionsTheme(
builders: {
// Use PredictiveBackPageTransitionsBuilder to get the predictive back route transition!
TargetPlatform.android: PredictiveBackPageTransitionsBuilder(),
},
),
),
home: const MyApp(),
); Though there's a lot of setup to do now, the idea is that this will all be the default in the long run. In the future native Android will support predictive back out of the box, and Flutter Android apps will default to the PredictiveBackPageTransitionsBuilder transitions. Can I write my own predictive back route transition?I wouldn't recommend it, yet. I plan to make some APIs public that will make this easier in the future. If you really want to mess with this now, look at how PredictiveBackPageTransitionsBuilder is implemented. OpenContainer transitions with predictive backCurrently OpenContainer transitions don't support predictive back, but I'm working on (flutter/packages#6321) supporting them out of the box soon. I'm talking about the kind of transitions where the popped route transitions back into some element on the previous page, which is currently done with the animations package. |
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 |
umbrella issue for the adding support for the Android 14 feature, Predictive back navigation.
The text was updated successfully, but these errors were encountered: