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

[go_router] guard context access in then clauses #6685

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions packages/go_router/lib/src/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class GoRouteInformationParser extends RouteInformationParser<RouteMatchList> {
return debugParserFuture = _redirect(context, matchList)
.then<RouteMatchList>((RouteMatchList value) {
if (value.isError && onParserException != null) {
// TODO(chunhtai): Figure out what to return if context is invalid.
// ignore: use_build_context_synchronously
return onParserException!(context, value);
}
return value;
Expand Down Expand Up @@ -106,6 +108,8 @@ class GoRouteInformationParser extends RouteInformationParser<RouteMatchList> {
initialMatches,
).then<RouteMatchList>((RouteMatchList matchList) {
if (matchList.isError && onParserException != null) {
// TODO(chunhtai): Figure out what to return if context is invalid.
// ignore: use_build_context_synchronously
return onParserException!(context, matchList);
}

Expand Down
4 changes: 4 additions & 0 deletions packages/go_router_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.6.2

* Fixes a bug in the example app when accessing `BuildContext`.

## 2.6.1

* Fixes typo in `durationDecoderHelperName`.
Expand Down
3 changes: 3 additions & 0 deletions packages/go_router_builder/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ class HomeScreen extends StatelessWidget {
unawaited(FamilyCountRoute(familyData.length)
.push<int>(context)
.then((int? value) {
if (!context.mounted) {
return;
}
if (value != null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
Expand Down
2 changes: 1 addition & 1 deletion packages/go_router_builder/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: go_router_builder
description: >-
A builder that supports generated strongly-typed route helpers for
package:go_router
version: 2.6.1
version: 2.6.2
repository: https://github.com/flutter/packages/tree/main/packages/go_router_builder
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router_builder%22

Expand Down