diff --git a/src/release/breaking-changes/android-predictive-back.md b/src/release/breaking-changes/android-predictive-back.md index a431e6bf6d..a2949cfe48 100644 --- a/src/release/breaking-changes/android-predictive-back.md +++ b/src/release/breaking-changes/android-predictive-back.md @@ -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
+Landed in version: 3.14.0-7.0.pre
In stable release: not yet ## References