Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
105 changes: 105 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,105 @@
---
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` didn't have a way to access the pop result when `onPopInvoked`
was called. The generic type is added to the `PopScope` class
so that `onPopInvoked` can access the type-safe result.
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
was called. The generic type is added to the `PopScope` class
so that `onPopInvoked` can access the type-safe result.
was called. The generic type added to the `PopScope` class
enables `onPopInvoked` access the type-safe result.


## Description of change

Added a generic type in `PopScope` class and updated the `onPopInvoked`
function signature to take 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`]
that the `PopScope` is in.
If the route uses `int` as its generic type, consider using `PopScope<int>`.

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

## Timeline

Landed in version: 3.22.0-12.0.pre-56
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