Skip to content

Update predictive back docs - #13640

Open
jesskuras wants to merge 6 commits into
flutter:mainfrom
jesskuras:update-predictive-back-docs
Open

Update predictive back docs#13640
jesskuras wants to merge 6 commits into
flutter:mainfrom
jesskuras:update-predictive-back-docs

Conversation

@jesskuras

@jesskuras jesskuras commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Fixes #13604

Summary

Updates documentation across the site to reflect the current state of Android predictive back support (Android 14+ default enablement) and recent API migrations:

  • Primary Predictive Back Guide (platform-integration/android/predictive-back.md): Updated support status, documented Android manifest setup (enableOnBackInvokedCallback="true"), and added a usage example for PopScope with onPopInvokedWithResult(bool didPop, Object? result).
  • Breaking Changes Guide (release/breaking-changes/android-predictive-back.md): Updated code snippets from onPopInvoked to onPopInvokedWithResult and refactored the setup section to delegate to the primary predictive back guide to avoid duplication.
  • Navigation Index (ui/navigation/index.md): Replaced deprecated WillPopScope references with PopScope.
  • Add-to-App Android Fragment Docs (add-to-app/android/add-flutter-fragment.md): Added documentation and Kotlin/Java examples for configuring shouldAutomaticallyHandleOnBackPressed(true).

Staged pages

@jesskuras
jesskuras requested a review from parlough July 28, 2026 22:43
@jesskuras
jesskuras requested review from a team and sfshaza2 as code owners July 28, 2026 22:43

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the documentation for Android predictive back gesture support in Flutter, including instructions for FlutterFragment, PopScope migration, and related breaking changes. A typo was found in the breaking changes document where 'WithResult' was duplicated in a section header.

Comment thread sites/docs/src/content/release/breaking-changes/android-predictive-back.md Outdated
@flutter-website-bot

flutter-website-bot commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Staged preview of the updated docs.flutter.dev site (updated for commit fc35846):

https://flutter-docs-prod--docs-pr13640-update-predictive-back-3ae2ylff.web.app

@flutter-website-bot

flutter-website-bot commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Staged preview of the updated flutter.dev site (updated for commit fc35846):

https://flutter-dev-230821--www-pr13640-update-predictive-back-tmpj9jhe.web.app

@parlough
parlough requested a review from justinmc July 28, 2026 23:03
jesskuras and others added 2 commits July 30, 2026 15:02
…tive-back.md

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

@justinmc justinmc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one clarification below, otherwise looks good.

Comment on lines +21 to +22
To support predictive back gestures in your Flutter application on
Android 13+:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Android 16 and above now sets enableOnBackInvokedCallback to true by default, so this step is only required on 13-15.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then these steps don't hurt for Android 16+ then either, right? It'd be nice to avoid making this conditional, since I guess many Android app developers want to support versions before 16 at this point anyway.

@parlough parlough left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this @jesskuras!

Some suggestions and notes to consider. Feel free to take or leave them.

The `PopScope` class directly replaces `WillPopScope` in order to enable
predictive back. Instead of deciding whether a pop is possible at the time it
occurs, this is set ahead of time with the `canPop` boolean. You can still
listen to pops by using `onPopInvoked`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
listen to pops by using `onPopInvokedWithResult`.

used in a similar way to `onWillPop`. Keep in mind
that while `onWillPop` was called before the pop
was handled and had the ability to cancel it,
`onPopInvoked` is called after the pop is finished being handled.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`onPopInvokedWithResult` is called after the pop is finished being handled.

```

For cases where it's necessary to be notified that a
pop was attempted, the `onPopInvoked` method can be

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pop was attempted, the `onPopInvokedWithResult` method can be

predictive back. If needed, use `PopScope` instead.
1. Run the app and perform a back gesture (swipe from the
left side of the screen).
For complete setup instructions, guidelines on predictive back gesture

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love redirecting to the primary doc rather than trying to repeat this and keep it updated. Thanks!

)
```

### Migrating from Form.onWillPop to Form.canPop and Form.onPopInvoked

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Migrating from Form.onWillPop to Form.canPop and Form.onPopInvokedWithResult

Comment on lines +51 to +52
* `result`: An optional return payload passed when popping the route
(for example, via `Navigator.pop(context, result)`).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://developers.google.com/style/word-list#via

Suggested change
* `result`: An optional return payload passed when popping the route
(for example, via `Navigator.pop(context, result)`).
* `result`: An optional return payload passed when popping the route,
for example, with `Navigator.pop(context, result)`.

```

[Android predictive back]: /release/breaking-changes/android-predictive-back
For more details on API migrations, check out the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider placing this in its own section as it seems separate from the proceeding example.

Suggested change
For more details on API migrations, check out the
## More information
For more details on API migrations, check out the

## Handle back gestures with PopScope

To customize back navigation or prevent users from accidentally leaving a
screen, use the `PopScope` widget. `PopScope` replaces the deprecated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider linking the first use of PopScope to its API docs: https://api.flutter.dev/flutter/widgets/PopScope-class.html

(for example, via `Navigator.pop(context, result)`).

* [Android predictive back][] breaking change
### Example: Intercepting back navigation

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the addition of an example!

```dart
return PopScope(
canPop: false,
onPopInvoked: (bool didPop) async {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
onPopInvokedWithResult: (bool didPop, Object? result) async {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update Android predictive back and related docs

4 participants