Skip to content
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

Add instructions for how to use Android's predictive back feature #10821

Closed
1 task
sfshaza2 opened this issue Jun 27, 2024 · 1 comment · Fixed by #10869
Closed
1 task

Add instructions for how to use Android's predictive back feature #10821

sfshaza2 opened this issue Jun 27, 2024 · 1 comment · Fixed by #10869
Assignees
Labels
co.request Community ask for documentation e2-days Effort: < 5 days p2-medium Necessary but not urgent concern. Resolve when possible.
Milestone

Comments

@sfshaza2
Copy link
Contributor

What information needs to be added?

This feature has been added, but is currently behind a flag. We could use some instructions on how to use this feature and @justinmc has said he can provide that here.

Where should this new content appear?

Probably as a brief migration guide (under release) for now.

I would like to fix this problem.

  • I will try and fix this problem on docs.flutter.dev.
@sfshaza2 sfshaza2 added the co.request Community ask for documentation label Jun 27, 2024
@sfshaza2 sfshaza2 self-assigned this Jun 27, 2024
@sfshaza2 sfshaza2 added p2-medium Necessary but not urgent concern. Resolve when possible. e2-days Effort: < 5 days labels Jun 27, 2024
@sfshaza2 sfshaza2 added this to the Q3 release 2024 milestone Jun 27, 2024
@justinmc
Copy link
Contributor

This feature has landed in Flutter, but it's not enabled by default in Android itself yet! To try it out yourself, there are a few hoops to jump through.

Configuring your app

Make sure your app supports Android API 33 or higher, as predictive back won't work on older versions of Android. Then, set the flag android:enableOnBackInvokedCallback="true" in android/app/src/main/AndroidManifest.xml.

Configuring your device

That's right, you need to enable Developer Mode and set a flag on your device, so you can't yet expect predictive back to work on most users' Android devices. If you want to try it out on your own device though, make sure it's running API 33 or higher, and then in Settings => System => Developer options, make sure the switch is enabled next to "Predictive back animations".

Setup your app

The predictive back route transitions are currently not enabled by default, so for now you'll need to enable them manually in your app. Typically you'll do this by setting them in your theme:

MaterialApp(
  theme: ThemeData(
    pageTransitionsTheme: const PageTransitionsTheme(
      builders: <TargetPlatform, PageTransitionsBuilder>{
        // Here is where I've set the predictive back transitions for Android.
        TargetPlatform.android: PredictiveBackPageTransitionsBuilder(),
      },
    ),
  ),
  ...
),

Running your app

Lastly, just make sure you're using at least Flutter version 3.22.2 to run your app, which is the latest stable release at the time of this writing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
co.request Community ask for documentation e2-days Effort: < 5 days p2-medium Necessary but not urgent concern. Resolve when possible.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants