Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[go_router] Fixes crashes when dynamically updates routing tables wit… #5242

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
## 12.0.3

- Fixes crashes when dynamically updates routing tables with named routes.

## 12.0.2

- Fixes the problem that pathParameters is null in redirect when the Router is recreated.
Expand Down
2 changes: 1 addition & 1 deletion packages/go_router/example/lib/routing_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class _MyAppState extends State<MyApp> {
return Scaffold(
appBar: AppBar(title: const Text('Home')),
body: Center(
child: Row(
child: Column(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is easy to overflow with row in phone screen

mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
Expand Down
1 change: 1 addition & 0 deletions packages/go_router/lib/src/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class RouteConfiguration {
assert(_debugCheckParentNavigatorKeys(
routingTable.routes, <GlobalKey<NavigatorState>>[navigatorKey]));
assert(_debugCheckStatefulShellBranchDefaultLocations(routingTable.routes));
_nameToPath.clear();
_cacheNameToPath('', routingTable.routes);
log(debugKnownRoutes());
}
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: 12.0.2
version: 12.0.3
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
44 changes: 44 additions & 0 deletions packages/go_router/test/routing_config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,48 @@ void main() {
await tester.pumpAndSettle();
expect(find.text('error'), findsOneWidget);
});

testWidgets('routing config works with named route',
(WidgetTester tester) async {
final ValueNotifier<RoutingConfig> config = ValueNotifier<RoutingConfig>(
RoutingConfig(
routes: <RouteBase>[
GoRoute(path: '/', builder: (_, __) => const Text('home')),
GoRoute(
path: '/abc',
name: 'abc',
builder: (_, __) => const Text('/abc')),
],
),
);
final GoRouter router = await createRouterWithRoutingConfig(
config,
tester,
errorBuilder: (_, __) => const Text('error'),
);
expect(find.text('home'), findsOneWidget);
// Sanity check.
router.goNamed('abc');
await tester.pumpAndSettle();
expect(find.text('/abc'), findsOneWidget);

config.value = RoutingConfig(
routes: <RouteBase>[
GoRoute(
path: '/', name: 'home', builder: (_, __) => const Text('home')),
GoRoute(
path: '/abc', name: 'def', builder: (_, __) => const Text('def')),
],
);
await tester.pumpAndSettle();
expect(find.text('def'), findsOneWidget);

router.goNamed('home');
await tester.pumpAndSettle();
expect(find.text('home'), findsOneWidget);

router.goNamed('def');
await tester.pumpAndSettle();
expect(find.text('def'), findsOneWidget);
});
}