Skip to content

Commit 8b91c0f

Browse files
chunhtaiTecHaxter
authored andcommitted
[go_router] Fixes an issue where route future does not complete when … (flutter#6596)
�popping shell route. fixes flutter/flutter#147196
1 parent 1b09202 commit 8b91c0f

File tree

4 files changed

+58
-3
lines changed

4 files changed

+58
-3
lines changed

packages/go_router/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 13.2.5
2+
3+
- Fixes an issue where route future does not complete when popping shell route.
4+
15
## 13.2.4
26

37
- Updates examples to use uri.path instead of uri.toString() for accessing the current location.

packages/go_router/lib/src/delegate.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,12 @@ class GoRouterDelegate extends RouterDelegate<RouteMatchList>
147147
}
148148

149149
void _completeRouteMatch(Object? result, RouteMatchBase match) {
150-
if (match is ImperativeRouteMatch) {
151-
match.complete(result);
150+
RouteMatchBase walker = match;
151+
while (walker is ShellRouteMatch) {
152+
walker = walker.matches.last;
153+
}
154+
if (walker is ImperativeRouteMatch) {
155+
walker.complete(result);
152156
}
153157
currentConfiguration = currentConfiguration.remove(match);
154158
notifyListeners();

packages/go_router/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: go_router
22
description: A declarative router for Flutter based on Navigation 2 supporting
33
deep linking, data-driven routes and more
4-
version: 13.2.4
4+
version: 13.2.5
55
repository: https://github.com/flutter/packages/tree/main/packages/go_router
66
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22
77

packages/go_router/test/go_router_test.dart

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3462,6 +3462,53 @@ void main() {
34623462
expect(find.text('Screen B'), findsOneWidget);
34633463
});
34643464

3465+
testWidgets('can complete leaf route', (WidgetTester tester) async {
3466+
Future<bool?>? routeFuture;
3467+
final List<RouteBase> routes = <RouteBase>[
3468+
GoRoute(
3469+
path: '/',
3470+
builder: (BuildContext context, GoRouterState state) {
3471+
return Scaffold(
3472+
body: TextButton(
3473+
onPressed: () async {
3474+
routeFuture = context.push<bool>('/a');
3475+
},
3476+
child: const Text('press'),
3477+
),
3478+
);
3479+
},
3480+
),
3481+
ShellRoute(
3482+
builder: (BuildContext context, GoRouterState state, Widget child) {
3483+
return Scaffold(
3484+
body: child,
3485+
);
3486+
},
3487+
routes: <RouteBase>[
3488+
GoRoute(
3489+
path: '/a',
3490+
builder: (BuildContext context, GoRouterState state) {
3491+
return const Scaffold(
3492+
body: Text('Screen A'),
3493+
);
3494+
},
3495+
),
3496+
],
3497+
),
3498+
];
3499+
3500+
final GoRouter router = await createRouter(routes, tester);
3501+
expect(find.text('press'), findsOneWidget);
3502+
3503+
await tester.tap(find.text('press'));
3504+
await tester.pumpAndSettle();
3505+
expect(find.text('Screen A'), findsOneWidget);
3506+
3507+
router.pop<bool>(true);
3508+
final bool? result = await routeFuture;
3509+
expect(result, isTrue);
3510+
});
3511+
34653512
testWidgets(
34663513
'Pops from the correct Navigator when the Android back button is pressed',
34673514
(WidgetTester tester) async {

0 commit comments

Comments
 (0)