Skip to content

Commit

Permalink
[go_router] Fixes an issue where route future does not complete when … (
Browse files Browse the repository at this point in the history
#6596)

�popping shell route.

fixes flutter/flutter#147196
  • Loading branch information
chunhtai committed Apr 24, 2024
1 parent 179f925 commit 890ec36
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/go_router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
8 changes: 6 additions & 2 deletions packages/go_router/lib/src/delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,12 @@ class GoRouterDelegate extends RouterDelegate<RouteMatchList>
}

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();
Expand Down
2 changes: 1 addition & 1 deletion packages/go_router/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
47 changes: 47 additions & 0 deletions packages/go_router/test/go_router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3462,6 +3462,53 @@ void main() {
expect(find.text('Screen B'), findsOneWidget);
});

testWidgets('can complete leaf route', (WidgetTester tester) async {
Future<bool?>? routeFuture;
final List<RouteBase> routes = <RouteBase>[
GoRoute(
path: '/',
builder: (BuildContext context, GoRouterState state) {
return Scaffold(
body: TextButton(
onPressed: () async {
routeFuture = context.push<bool>('/a');
},
child: const Text('press'),
),
);
},
),
ShellRoute(
builder: (BuildContext context, GoRouterState state, Widget child) {
return Scaffold(
body: child,
);
},
routes: <RouteBase>[
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<bool>(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 {
Expand Down

0 comments on commit 890ec36

Please sign in to comment.