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

Predictive back migration guide confirmation dialog example #9244

Merged
merged 6 commits into from
Aug 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/release/breaking-changes/android-predictive-back.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
parlough marked this conversation as resolved.
Show resolved Hide resolved

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<br>
parlough marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading