Skip to content

Commit cccf5d2

Browse files
authored
[go_router] Fixes crashes when dynamically updates routing tables wit… (flutter#5242)
�h named routes. fixes flutter#137133
1 parent 5b03a38 commit cccf5d2

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
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+
## 12.0.3
2+
3+
- Fixes crashes when dynamically updates routing tables with named routes.
4+
15
## 12.0.2
26

37
- Fixes the problem that pathParameters is null in redirect when the Router is recreated.

packages/go_router/example/lib/routing_config.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class _MyAppState extends State<MyApp> {
4848
return Scaffold(
4949
appBar: AppBar(title: const Text('Home')),
5050
body: Center(
51-
child: Row(
51+
child: Column(
5252
mainAxisAlignment: MainAxisAlignment.center,
5353
children: <Widget>[
5454
ElevatedButton(

packages/go_router/lib/src/configuration.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ class RouteConfiguration {
196196
assert(_debugCheckParentNavigatorKeys(
197197
routingTable.routes, <GlobalKey<NavigatorState>>[navigatorKey]));
198198
assert(_debugCheckStatefulShellBranchDefaultLocations(routingTable.routes));
199+
_nameToPath.clear();
199200
_cacheNameToPath('', routingTable.routes);
200201
log(debugKnownRoutes());
201202
}

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: 12.0.2
4+
version: 12.0.3
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/routing_config_test.dart

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,48 @@ void main() {
106106
await tester.pumpAndSettle();
107107
expect(find.text('error'), findsOneWidget);
108108
});
109+
110+
testWidgets('routing config works with named route',
111+
(WidgetTester tester) async {
112+
final ValueNotifier<RoutingConfig> config = ValueNotifier<RoutingConfig>(
113+
RoutingConfig(
114+
routes: <RouteBase>[
115+
GoRoute(path: '/', builder: (_, __) => const Text('home')),
116+
GoRoute(
117+
path: '/abc',
118+
name: 'abc',
119+
builder: (_, __) => const Text('/abc')),
120+
],
121+
),
122+
);
123+
final GoRouter router = await createRouterWithRoutingConfig(
124+
config,
125+
tester,
126+
errorBuilder: (_, __) => const Text('error'),
127+
);
128+
expect(find.text('home'), findsOneWidget);
129+
// Sanity check.
130+
router.goNamed('abc');
131+
await tester.pumpAndSettle();
132+
expect(find.text('/abc'), findsOneWidget);
133+
134+
config.value = RoutingConfig(
135+
routes: <RouteBase>[
136+
GoRoute(
137+
path: '/', name: 'home', builder: (_, __) => const Text('home')),
138+
GoRoute(
139+
path: '/abc', name: 'def', builder: (_, __) => const Text('def')),
140+
],
141+
);
142+
await tester.pumpAndSettle();
143+
expect(find.text('def'), findsOneWidget);
144+
145+
router.goNamed('home');
146+
await tester.pumpAndSettle();
147+
expect(find.text('home'), findsOneWidget);
148+
149+
router.goNamed('def');
150+
await tester.pumpAndSettle();
151+
expect(find.text('def'), findsOneWidget);
152+
});
109153
}

0 commit comments

Comments
 (0)