diff --git a/packages/go_router/CHANGELOG.md b/packages/go_router/CHANGELOG.md index 576a71789a7c..4cb037ef2ada 100644 --- a/packages/go_router/CHANGELOG.md +++ b/packages/go_router/CHANGELOG.md @@ -1,3 +1,7 @@ +## 13.2.5 + +- Fixes an issue where route future does not complete when popping shell route. + ## 13.2.4 - Updates examples to use uri.path instead of uri.toString() for accessing the current location. diff --git a/packages/go_router/lib/src/delegate.dart b/packages/go_router/lib/src/delegate.dart index 3b01b9e381c8..bf5840cbad4c 100644 --- a/packages/go_router/lib/src/delegate.dart +++ b/packages/go_router/lib/src/delegate.dart @@ -147,8 +147,12 @@ class GoRouterDelegate extends RouterDelegate } void _completeRouteMatch(Object? result, RouteMatchBase match) { - if (match is ImperativeRouteMatch) { - match.complete(result); + RouteMatchBase walker = match; + while (walker is ShellRouteMatch) { + walker = walker.matches.last; + } + if (walker is ImperativeRouteMatch) { + walker.complete(result); } currentConfiguration = currentConfiguration.remove(match); notifyListeners(); diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml index 29dfaa27a447..25ec466df0d2 100644 --- a/packages/go_router/pubspec.yaml +++ b/packages/go_router/pubspec.yaml @@ -1,7 +1,7 @@ name: go_router description: A declarative router for Flutter based on Navigation 2 supporting deep linking, data-driven routes and more -version: 13.2.4 +version: 13.2.5 repository: https://github.com/flutter/packages/tree/main/packages/go_router issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22 diff --git a/packages/go_router/test/go_router_test.dart b/packages/go_router/test/go_router_test.dart index 57d8612c0767..42bbec0cc4f8 100644 --- a/packages/go_router/test/go_router_test.dart +++ b/packages/go_router/test/go_router_test.dart @@ -3462,6 +3462,53 @@ void main() { expect(find.text('Screen B'), findsOneWidget); }); + testWidgets('can complete leaf route', (WidgetTester tester) async { + Future? routeFuture; + final List routes = [ + GoRoute( + path: '/', + builder: (BuildContext context, GoRouterState state) { + return Scaffold( + body: TextButton( + onPressed: () async { + routeFuture = context.push('/a'); + }, + child: const Text('press'), + ), + ); + }, + ), + ShellRoute( + builder: (BuildContext context, GoRouterState state, Widget child) { + return Scaffold( + body: child, + ); + }, + routes: [ + GoRoute( + path: '/a', + builder: (BuildContext context, GoRouterState state) { + return const Scaffold( + body: Text('Screen A'), + ); + }, + ), + ], + ), + ]; + + final GoRouter router = await createRouter(routes, tester); + expect(find.text('press'), findsOneWidget); + + await tester.tap(find.text('press')); + await tester.pumpAndSettle(); + expect(find.text('Screen A'), findsOneWidget); + + router.pop(true); + final bool? result = await routeFuture; + expect(result, isTrue); + }); + testWidgets( 'Pops from the correct Navigator when the Android back button is pressed', (WidgetTester tester) async {