Skip to content

Commit

Permalink
[go_router] guard context access in then clauses (#6685)
Browse files Browse the repository at this point in the history
Prepares for a fix to the `use_build_context_synchronously` lint (https://dart-review.googlesource.com/c/sdk/+/365541) that will complain about these unsafe usages.
  • Loading branch information
goderbauer authored May 7, 2024
1 parent 55499d8 commit 4595c41
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
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

0 comments on commit 4595c41

Please sign in to comment.