Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
2 changes: 2 additions & 0 deletions src/content/release/breaking-changes/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ release, and listed in alphabetical order:

### Not yet released to stable

* [Generic types in `PopScope`][]
* [Rename `MaterialState` to `WidgetState`][]
* [Introduce new `ColorScheme` roles][]
* [Stop generating `AssetManifest.json`][]
Expand All @@ -43,6 +44,7 @@ release, and listed in alphabetical order:
* [Deprecated API removed after v3.19][]
* [Dropping support for Android KitKat][]

[Generic types in `PopScope`]: /release/breaking-changes/popscope-with-result
[Rename `MaterialState` to `WidgetState`]: /release/breaking-changes/material-state
[Introduce new `ColorScheme` roles]: /release/breaking-changes/new-color-scheme-roles
[Stop generating `AssetManifest.json`]: /release/breaking-changes/asset-manifest-dot-json
Expand Down
104 changes: 104 additions & 0 deletions src/content/release/breaking-changes/popscope-with-result.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
title: Generic types in PopScope
description: >
Added a generic type in PopScope class and updated the onPopInvoked
function signature.
---

## Summary

Added a generic type in [`PopScope`][] class and updated the [`onPopInvoked`][]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Added a generic type in [`PopScope`][] class and updated the [`onPopInvoked`][]
Added a generic type in the [`PopScope`][] class and updated the [`onPopInvoked`][]

function signature to take in an additional result as an position parameter.

## Context

Previously, PopScope hadn't haven a way to access the pop result when `onPopInvoked`
is called. To add support for accessing pop result, the generic type is added to
PopScope class so that the `onPopInvoked` can access the type-safe result.

## Description of change

Added a generic type in `PopScope` class and updated the `onPopInvoked`
function signature to take in an additional result as an position parameter.

## Migration guide

Code before migration

```dart
import 'package:flutter/material.dart';

void main() {
runApp(
MaterialApp(
navigatorKey: nav,
home: PopScope(
canPop: false,
onPopInvoked: (bool didPop) {
if (didPop) {
return;
}
launchConfirmationDialog();
},
child: MyWidget(),
),
),
);
}
```

Code after migration
```dart
import 'package:flutter/material.dart';

void main() {
runApp(
MaterialApp(
navigatorKey: nav,
home: PopScope<Object?>(
canPop: false,
onPopInvoked: (bool didPop, Object? result) {
if (didPop) {
return;
}
launchConfirmationDialog();
},
child: MyWidget(),
),
),
);
}
```

The generic type should match the generic type of the [`Route`] the `PopScope` is in.
If the route uses `int` as its generic type, consider use `PopScope<int>`.

If the widget are shared across multiple routes with different types, one can
use `PopScope<Object?>` to catch all possible types.

## Timeline

Landed in version: TBD
Copy link
Contributor Author

Choose a reason for hiding this comment

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

will fill this out when pr merges. It would require internal migration, so may take some time

In stable release: TBD

## References

API documentation:

* [`PopScope`][]
* [`onPopInvoked`][]
* [`Route`][]

Relevant issue:

* [Issue 137458][]

Relevant PR:

* [Add generic type for result in PopScope][]

[Add generic type for result in PopScope]: {{site.repo.flutter}}/pull/139164
[`PopScope`]: {{site.api}}/flutter/widgets/PopScope-class.html
[`Route`]: {{site.api}}/flutter/widgets/Route-class.html
[`onPopInvoked`]: {{site.api}}/flutter/widgets/PopScope/onPopInvoked.html
[Issue 137458]: {{site.repo.flutter}}/issues/137458