Skip to content

Commit

Permalink
[go_router] Fixes crashes when dynamically updates routing tables wit… (
Browse files Browse the repository at this point in the history
#5242)

�h named routes.
fixes flutter/flutter#137133
  • Loading branch information
chunhtai committed Nov 2, 2023
1 parent 5b03a38 commit cccf5d2
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
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(
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);
});
}

0 comments on commit cccf5d2

Please sign in to comment.