From 43d6f99a56fb447d45e44a06448bd0d3336f03ca Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Tue, 7 May 2024 10:53:11 -0700 Subject: [PATCH 1/3] [go_router] guard context access in then clauses --- packages/go_router/lib/src/parser.dart | 4 ++-- packages/go_router_builder/example/lib/main.dart | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/go_router/lib/src/parser.dart b/packages/go_router/lib/src/parser.dart index bffcd1b15b62..662ba5642936 100644 --- a/packages/go_router/lib/src/parser.dart +++ b/packages/go_router/lib/src/parser.dart @@ -72,7 +72,7 @@ class GoRouteInformationParser extends RouteInformationParser { return debugParserFuture = _redirect(context, matchList) .then((RouteMatchList value) { if (value.isError && onParserException != null) { - return onParserException!(context, value); + return onParserException!(context, value); // ignore: use_build_context_synchronously } return value; }); @@ -106,7 +106,7 @@ class GoRouteInformationParser extends RouteInformationParser { initialMatches, ).then((RouteMatchList matchList) { if (matchList.isError && onParserException != null) { - return onParserException!(context, matchList); + return onParserException!(context, matchList); // ignore: use_build_context_synchronously } assert(() { diff --git a/packages/go_router_builder/example/lib/main.dart b/packages/go_router_builder/example/lib/main.dart index b67ca5f5aa85..d555649825ac 100644 --- a/packages/go_router_builder/example/lib/main.dart +++ b/packages/go_router_builder/example/lib/main.dart @@ -188,6 +188,9 @@ class HomeScreen extends StatelessWidget { unawaited(FamilyCountRoute(familyData.length) .push(context) .then((int? value) { + if (!context.mounted) { + return; + } if (value != null) { ScaffoldMessenger.of(context).showSnackBar( SnackBar( From 4f22503a8a8bb8b0c1b6effd92d1c4b3dbdb441f Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Tue, 7 May 2024 11:25:55 -0700 Subject: [PATCH 2/3] fix formatting, add TODO --- packages/go_router/lib/src/parser.dart | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/go_router/lib/src/parser.dart b/packages/go_router/lib/src/parser.dart index 662ba5642936..b4115a1fca19 100644 --- a/packages/go_router/lib/src/parser.dart +++ b/packages/go_router/lib/src/parser.dart @@ -72,7 +72,9 @@ class GoRouteInformationParser extends RouteInformationParser { return debugParserFuture = _redirect(context, matchList) .then((RouteMatchList value) { if (value.isError && onParserException != null) { - return onParserException!(context, value); // ignore: use_build_context_synchronously + // TODO(chunhtai): Figure out what to return if context is invalid. + // ignore: use_build_context_synchronously + return onParserException!(context, value); } return value; }); @@ -106,7 +108,9 @@ class GoRouteInformationParser extends RouteInformationParser { initialMatches, ).then((RouteMatchList matchList) { if (matchList.isError && onParserException != null) { - return onParserException!(context, matchList); // ignore: use_build_context_synchronously + // TODO(chunhtai): Figure out what to return if context is invalid. + // ignore: use_build_context_synchronously + return onParserException!(context, matchList); } assert(() { From b93dba1e736c81af5ec74d9218f767204b1a8bff Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Tue, 7 May 2024 12:30:23 -0700 Subject: [PATCH 3/3] ++ --- packages/go_router_builder/CHANGELOG.md | 4 ++++ packages/go_router_builder/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/go_router_builder/CHANGELOG.md b/packages/go_router_builder/CHANGELOG.md index 2a490e34200e..dd2b10f30a1e 100644 --- a/packages/go_router_builder/CHANGELOG.md +++ b/packages/go_router_builder/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.6.2 + +* Fixes a bug in the example app when accessing `BuildContext`. + ## 2.6.1 * Fixes typo in `durationDecoderHelperName`. diff --git a/packages/go_router_builder/pubspec.yaml b/packages/go_router_builder/pubspec.yaml index c64c3341243e..82b41bb5f67a 100644 --- a/packages/go_router_builder/pubspec.yaml +++ b/packages/go_router_builder/pubspec.yaml @@ -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