-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Adds popscope migration guide #9872
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/content/release/breaking-changes/popscope-with-result.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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`][] | ||
| 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. | ||
chunhtai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## 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. | ||
chunhtai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## 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>`. | ||
chunhtai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| If the widget are shared across multiple routes with different types, one can | ||
| use `PopScope<Object?>` to catch all possible types. | ||
chunhtai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Timeline | ||
|
|
||
| Landed in version: TBD | ||
|
||
| 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 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.