Skip to content

Commit

Permalink
Predictive back migration guide confirmation dialog example (#9244)
Browse files Browse the repository at this point in the history
A user requested this example be added to the migration guide [on
Discord](https://discord.com/channels/608014603317936148/969301283825659914/1140422179511603290).
I think it's a reasonable request.

Follow up on: #8952
Framework PR: flutter/flutter#132249

---------

Co-authored-by: Parker Lougheed <parlough@gmail.com>
  • Loading branch information
justinmc and parlough authored Aug 21, 2023
1 parent 34bebf8 commit c42ad96
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion src/release/breaking-changes/android-predictive-back.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,60 @@ if (_route.popDisposition == RoutePopDisposition.doNotPop) {
}
```

### Migrating a back confirmation dialog

`WillPopScope` was sometimes used to show a confirmation dialog when
a back gesture was received.
This can still be done with `PopScope` in a similar pattern.

Code before migration:

```dart
WillPopScope(
onWillPop: () async {
final bool? shouldPop = await _showBackDialog();
return shouldPop ?? false;
},
child: child,
)
```

Code after migration:

```dart
return PopScope(
canPop: false,
onPopInvoked: (bool didPop) async {
if (didPop) {
return;
}
final NavigatorState navigator = Navigator.of(context);
final bool? shouldPop = await _showBackDialog();
if (shouldPop ?? false) {
navigator.pop();
}
},
child: child,
)
```

### Supporting predictive back

1. Run Android 33 or above.
1. Enable the feature flag for predictive back on
the device under "Developer options".
This will be unnecessary on future versions of Android.
1. Set `android:enableOnBackInvokedCallback="true"` in
`android/app/src/main/AndroidManifest.xml`. If needed, refer to
[Android's full guide](https://developer.android.com/guide/navigation/custom-back/predictive-back-gesture)
for migrating Android apps to support predictive back.
1. Make sure you're using version `3.14.0-7.0.pre` of Flutter or greater.
1. Run the app and perform a back gesture (swipe from the left side of
the screen).

## Timeline

Landed in version: 3.14.0-0.0.pre<br>
Landed in version: 3.14.0-7.0.pre<br>
In stable release: not yet

## References
Expand Down

0 comments on commit c42ad96

Please sign in to comment.