@@ -204,7 +204,9 @@ void main() {
204204
205205 test ('push scopes key collisions in nested ShellRouteMatch' , () {
206206 final leafRoute = GoRoute (path: '/leaf' , builder: _builder);
207- final nestedNavigatorKey = GlobalKey <NavigatorState >();
207+ // Deliberately create separate instances to verify value equality below.
208+ // ignore: prefer_const_constructors
209+ final nestedNavigatorKey = _ValueNavigatorKey ('nested' );
208210 final nestedRoute = ShellRoute (
209211 navigatorKey: nestedNavigatorKey,
210212 builder: _shellBuilder,
@@ -276,6 +278,61 @@ void main() {
276278 expect (pushedOuterMatch.navigatorKey, same (pushedOuterRoute.navigatorKey));
277279 expect (pushedNestedMatch.pageKey, isNot (nestedPageKey));
278280 expect (pushedNestedMatch.navigatorKey, isNot (equals (nestedNavigatorKey)));
281+
282+ // ignore: prefer_const_constructors
283+ final equivalentNestedNavigatorKey = _ValueNavigatorKey ('nested' );
284+ expect (equivalentNestedNavigatorKey, equals (nestedNavigatorKey));
285+ expect (equivalentNestedNavigatorKey, isNot (same (nestedNavigatorKey)));
286+ final equivalentLeafRoute = GoRoute (path: '/leaf' , builder: _builder);
287+ final equivalentNestedRoute = ShellRoute (
288+ navigatorKey: equivalentNestedNavigatorKey,
289+ builder: _shellBuilder,
290+ routes: < RouteBase > [equivalentLeafRoute],
291+ );
292+ final equivalentPushedOuterRoute = ShellRoute (
293+ builder: _shellBuilder,
294+ routes: < RouteBase > [equivalentNestedRoute],
295+ );
296+ final equivalentPushedMatchList = RouteMatchList (
297+ matches: < RouteMatchBase > [
298+ ShellRouteMatch (
299+ route: equivalentPushedOuterRoute,
300+ matches: < RouteMatchBase > [
301+ ShellRouteMatch (
302+ route: equivalentNestedRoute,
303+ matches: < RouteMatchBase > [
304+ RouteMatch (
305+ route: equivalentLeafRoute,
306+ matchedLocation: '/leaf' ,
307+ pageKey: const ValueKey <String >('/leaf' ),
308+ ),
309+ ],
310+ matchedLocation: '/leaf' ,
311+ pageKey: nestedPageKey,
312+ navigatorKey: equivalentNestedNavigatorKey,
313+ ),
314+ ],
315+ matchedLocation: '/leaf' ,
316+ pageKey: pushedOuterPageKey,
317+ navigatorKey: equivalentPushedOuterRoute.navigatorKey,
318+ ),
319+ ],
320+ uri: Uri .parse ('/leaf' ),
321+ pathParameters: const < String , String > {},
322+ );
323+ final RouteMatchList equivalentResult = currentMatchList.push (
324+ ImperativeRouteMatch (
325+ pageKey: const ValueKey <String >('push' ),
326+ matches: equivalentPushedMatchList,
327+ completer: Completer <void >(),
328+ ),
329+ );
330+ final equivalentPushedOuterMatch = equivalentResult.matches.last as ShellRouteMatch ;
331+ final equivalentPushedNestedMatch =
332+ equivalentPushedOuterMatch.matches.single as ShellRouteMatch ;
333+ expect (equivalentPushedNestedMatch.pageKey, pushedNestedMatch.pageKey);
334+ expect (equivalentPushedNestedMatch.pageKey.value, pushedNestedMatch.pageKey.value);
335+ expect (equivalentPushedNestedMatch.navigatorKey, pushedNestedMatch.navigatorKey);
279336 });
280337 });
281338}
@@ -284,3 +341,15 @@ Widget _builder(BuildContext context, GoRouterState state) => const Placeholder(
284341
285342Widget _shellBuilder (BuildContext context, GoRouterState state, Widget child) =>
286343 const Placeholder ();
344+
345+ class _ValueNavigatorKey extends GlobalKey <NavigatorState > {
346+ const _ValueNavigatorKey (this .label) : super .constructor ();
347+
348+ final String label;
349+
350+ @override
351+ bool operator == (Object other) => other is _ValueNavigatorKey && other.label == label;
352+
353+ @override
354+ int get hashCode => label.hashCode;
355+ }
0 commit comments