From 49376c9c8fa443e43f1936b5a7ccdad22380472e Mon Sep 17 00:00:00 2001 From: Justin McCandless Date: Mon, 14 Aug 2023 12:30:37 -0700 Subject: [PATCH 1/5] Add an example of migrating a confirmation dialog, requested on Discord --- .../android-predictive-back.md | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/release/breaking-changes/android-predictive-back.md b/src/release/breaking-changes/android-predictive-back.md index 6a603727a9..308dff2d35 100644 --- a/src/release/breaking-changes/android-predictive-back.md +++ b/src/release/breaking-changes/android-predictive-back.md @@ -270,6 +270,41 @@ 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, +) +``` + ## Timeline Landed in version: 3.13
From 0502cf3a4fe0da8ca9195334447033e4326c6bd1 Mon Sep 17 00:00:00 2001 From: Justin McCandless Date: Tue, 15 Aug 2023 12:26:15 -0700 Subject: [PATCH 2/5] Review fixes --- src/release/breaking-changes/android-predictive-back.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/release/breaking-changes/android-predictive-back.md b/src/release/breaking-changes/android-predictive-back.md index 308dff2d35..17d2147c65 100644 --- a/src/release/breaking-changes/android-predictive-back.md +++ b/src/release/breaking-changes/android-predictive-back.md @@ -271,8 +271,9 @@ 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. +`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: From 689bdf6264683da746eefdfd7f16e7058b98b11f Mon Sep 17 00:00:00 2001 From: Justin McCandless Date: Mon, 21 Aug 2023 09:22:31 -0700 Subject: [PATCH 3/5] Version number --- src/release/breaking-changes/android-predictive-back.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/release/breaking-changes/android-predictive-back.md b/src/release/breaking-changes/android-predictive-back.md index 17d2147c65..144098c831 100644 --- a/src/release/breaking-changes/android-predictive-back.md +++ b/src/release/breaking-changes/android-predictive-back.md @@ -308,7 +308,7 @@ return PopScope( ## Timeline -Landed in version: 3.13
+Landed in version: 3.14.0-7.0.pre
In stable release: not yet ## References From 19f92b91c1b545c73ebc93958a1994dfd778326a Mon Sep 17 00:00:00 2001 From: Justin McCandless Date: Mon, 21 Aug 2023 09:44:40 -0700 Subject: [PATCH 4/5] Add a section about supporting predictive back --- .../breaking-changes/android-predictive-back.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/release/breaking-changes/android-predictive-back.md b/src/release/breaking-changes/android-predictive-back.md index 1dce54c28c..13cd4064fd 100644 --- a/src/release/breaking-changes/android-predictive-back.md +++ b/src/release/breaking-changes/android-predictive-back.md @@ -306,6 +306,19 @@ return PopScope( ) ``` +### 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. Perform a back gesture (swipe from the left side of the + screen). + ## Timeline Landed in version: 3.14.0-7.0.pre
From 76630cf86c68ad3280f00cc9fe654cfce0c159a5 Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Mon, 21 Aug 2023 14:06:51 -0500 Subject: [PATCH 5/5] Formatting cleanup --- .../android-predictive-back.md | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/release/breaking-changes/android-predictive-back.md b/src/release/breaking-changes/android-predictive-back.md index 13cd4064fd..a2949cfe48 100644 --- a/src/release/breaking-changes/android-predictive-back.md +++ b/src/release/breaking-changes/android-predictive-back.md @@ -271,9 +271,10 @@ 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. + +`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: @@ -309,15 +310,16 @@ return PopScope( ### 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. 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/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. Perform a back gesture (swipe from the left side of the - screen). + 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