Skip to content

Commit d5feda5

Browse files
[go-router] Add ability to pop with result using extension #116506 (#3036)
* [go-router] Add ability to pop with result using extension #116506 * Increased version * Added a test to validate the result is captured * #116506 Changed dynamic to Object?
1 parent e9cb047 commit d5feda5

5 files changed

Lines changed: 23 additions & 2 deletions

File tree

packages/go_router/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 6.0.2
2+
3+
- Fixes missing result on pop in go_router extension.
4+
15
## 6.0.1
26

37
- Fixes crashes when popping navigators manually.

packages/go_router/lib/src/misc/extensions.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ extension GoRouterHelper on BuildContext {
5959

6060
/// Pop the top page off the Navigator's page stack by calling
6161
/// [Navigator.pop].
62-
void pop() => GoRouter.of(this).pop();
62+
void pop<T extends Object?>([T? result]) => GoRouter.of(this).pop(result);
6363

6464
/// Replaces the top-most page of the page stack with the given URL location
6565
/// w/ optional query parameters, e.g. `/family/f2/person/p1?color=blue`.

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: 6.0.1
4+
version: 6.0.2
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2681,6 +2681,21 @@ void main() {
26812681
);
26822682
key.currentContext!.pop();
26832683
expect(router.popped, true);
2684+
expect(router.poppedResult, null);
2685+
});
2686+
2687+
testWidgets('calls [pop] on closest GoRouter with result',
2688+
(WidgetTester tester) async {
2689+
final GoRouterPopSpy router = GoRouterPopSpy(routes: routes);
2690+
await tester.pumpWidget(
2691+
MaterialApp.router(
2692+
routerConfig: router,
2693+
title: 'GoRouter Example',
2694+
),
2695+
);
2696+
key.currentContext!.pop('result');
2697+
expect(router.popped, true);
2698+
expect(router.poppedResult, 'result');
26842699
});
26852700
});
26862701

packages/go_router/test/test_helpers.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,12 @@ class GoRouterPopSpy extends GoRouter {
127127
GoRouterPopSpy({required super.routes});
128128

129129
bool popped = false;
130+
Object? poppedResult;
130131

131132
@override
132133
void pop<T extends Object?>([T? result]) {
133134
popped = true;
135+
poppedResult = result;
134136
}
135137
}
136138

0 commit comments

Comments
 (0)