mirror of
https://github.com/flutter/packages.git
synced 2025-07-01 15:23:25 +08:00
* [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?
This commit is contained in:

committed by
GitHub

parent
e9cb0470ec
commit
d5feda5ad8
@ -1,3 +1,7 @@
|
|||||||
|
## 6.0.2
|
||||||
|
|
||||||
|
- Fixes missing result on pop in go_router extension.
|
||||||
|
|
||||||
## 6.0.1
|
## 6.0.1
|
||||||
|
|
||||||
- Fixes crashes when popping navigators manually.
|
- Fixes crashes when popping navigators manually.
|
||||||
|
@ -59,7 +59,7 @@ extension GoRouterHelper on BuildContext {
|
|||||||
|
|
||||||
/// Pop the top page off the Navigator's page stack by calling
|
/// Pop the top page off the Navigator's page stack by calling
|
||||||
/// [Navigator.pop].
|
/// [Navigator.pop].
|
||||||
void pop() => GoRouter.of(this).pop();
|
void pop<T extends Object?>([T? result]) => GoRouter.of(this).pop(result);
|
||||||
|
|
||||||
/// Replaces the top-most page of the page stack with the given URL location
|
/// Replaces the top-most page of the page stack with the given URL location
|
||||||
/// w/ optional query parameters, e.g. `/family/f2/person/p1?color=blue`.
|
/// w/ optional query parameters, e.g. `/family/f2/person/p1?color=blue`.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
name: go_router
|
name: go_router
|
||||||
description: A declarative router for Flutter based on Navigation 2 supporting
|
description: A declarative router for Flutter based on Navigation 2 supporting
|
||||||
deep linking, data-driven routes and more
|
deep linking, data-driven routes and more
|
||||||
version: 6.0.1
|
version: 6.0.2
|
||||||
repository: https://github.com/flutter/packages/tree/main/packages/go_router
|
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
|
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22
|
||||||
|
|
||||||
|
@ -2681,6 +2681,21 @@ void main() {
|
|||||||
);
|
);
|
||||||
key.currentContext!.pop();
|
key.currentContext!.pop();
|
||||||
expect(router.popped, true);
|
expect(router.popped, true);
|
||||||
|
expect(router.poppedResult, null);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('calls [pop] on closest GoRouter with result',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
final GoRouterPopSpy router = GoRouterPopSpy(routes: routes);
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp.router(
|
||||||
|
routerConfig: router,
|
||||||
|
title: 'GoRouter Example',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
key.currentContext!.pop('result');
|
||||||
|
expect(router.popped, true);
|
||||||
|
expect(router.poppedResult, 'result');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -127,10 +127,12 @@ class GoRouterPopSpy extends GoRouter {
|
|||||||
GoRouterPopSpy({required super.routes});
|
GoRouterPopSpy({required super.routes});
|
||||||
|
|
||||||
bool popped = false;
|
bool popped = false;
|
||||||
|
Object? poppedResult;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void pop<T extends Object?>([T? result]) {
|
void pop<T extends Object?>([T? result]) {
|
||||||
popped = true;
|
popped = true;
|
||||||
|
poppedResult = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user