mirror of
https://github.com/flutter/packages.git
synced 2025-07-02 08:34:31 +08:00
[go_router] Fix parentNavigatorKey not working with multiple nested Routes in ShellRoute (#2784)
* [go_router] Fix parentNavigatorKey with multiple nested Routes in ShellRoute (#111961) * Update packages/go_router/CHANGELOG.md Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com> Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com>
This commit is contained in:

committed by
GitHub

parent
1973a509a3
commit
6a03dd47ec
@ -1,3 +1,7 @@
|
|||||||
|
## 5.1.6
|
||||||
|
|
||||||
|
- Fixes crashes when multiple `GoRoute`s use the same `parentNavigatorKey` in a route subtree.
|
||||||
|
|
||||||
## 5.1.5
|
## 5.1.5
|
||||||
|
|
||||||
- Adds migration guide for 5.1.2 to readme.
|
- Adds migration guide for 5.1.2 to readme.
|
||||||
|
@ -60,9 +60,9 @@ class RouteConfiguration {
|
|||||||
checkParentNavigatorKeys(
|
checkParentNavigatorKeys(
|
||||||
route.routes,
|
route.routes,
|
||||||
<GlobalKey<NavigatorState>>[
|
<GlobalKey<NavigatorState>>[
|
||||||
// Once a parentNavigatorKey is used, only the navigator keys
|
// Once a parentNavigatorKey is used, only that navigator key
|
||||||
// above it can be used.
|
// or keys above it can be used.
|
||||||
...allowedKeys.sublist(0, allowedKeys.indexOf(parentKey)),
|
...allowedKeys.sublist(0, allowedKeys.indexOf(parentKey) + 1),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -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: 5.1.5
|
version: 5.1.6
|
||||||
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
|
||||||
|
|
||||||
|
@ -175,6 +175,55 @@ void main() {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'Does not throw with multiple nested GoRoutes using parentNavigatorKey in ShellRoute',
|
||||||
|
() {
|
||||||
|
final GlobalKey<NavigatorState> root =
|
||||||
|
GlobalKey<NavigatorState>(debugLabel: 'root');
|
||||||
|
final GlobalKey<NavigatorState> shell =
|
||||||
|
GlobalKey<NavigatorState>(debugLabel: 'shell');
|
||||||
|
RouteConfiguration(
|
||||||
|
navigatorKey: root,
|
||||||
|
routes: <RouteBase>[
|
||||||
|
ShellRoute(
|
||||||
|
navigatorKey: shell,
|
||||||
|
routes: <RouteBase>[
|
||||||
|
GoRoute(
|
||||||
|
path: '/',
|
||||||
|
builder: _mockScreenBuilder,
|
||||||
|
routes: <RouteBase>[
|
||||||
|
GoRoute(
|
||||||
|
path: 'a',
|
||||||
|
builder: _mockScreenBuilder,
|
||||||
|
parentNavigatorKey: root,
|
||||||
|
routes: <RouteBase>[
|
||||||
|
GoRoute(
|
||||||
|
path: 'b',
|
||||||
|
builder: _mockScreenBuilder,
|
||||||
|
parentNavigatorKey: root,
|
||||||
|
routes: <RouteBase>[
|
||||||
|
GoRoute(
|
||||||
|
path: 'c',
|
||||||
|
builder: _mockScreenBuilder,
|
||||||
|
parentNavigatorKey: root,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
redirectLimit: 10,
|
||||||
|
topRedirect: (BuildContext context, GoRouterState state) {
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test(
|
test(
|
||||||
'Throws when parentNavigatorKeys are overlapping',
|
'Throws when parentNavigatorKeys are overlapping',
|
||||||
() {
|
() {
|
||||||
@ -369,7 +418,6 @@ void main() {
|
|||||||
navigatorKey: root,
|
navigatorKey: root,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
test(
|
test(
|
||||||
'Does not throw with valid parentNavigatorKey configuration',
|
'Does not throw with valid parentNavigatorKey configuration',
|
||||||
@ -454,6 +502,7 @@ void main() {
|
|||||||
throwsAssertionError,
|
throwsAssertionError,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MockScreen extends StatelessWidget {
|
class _MockScreen extends StatelessWidget {
|
||||||
|
Reference in New Issue
Block a user