Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
fa4c542
Added NestedNavigationShellRoute, to support building nested persiste…
tolo Sep 26, 2022
76b17ae
Added example for NestedNavigationShellRoute.
tolo Sep 26, 2022
7612a55
Formatting.
tolo Sep 27, 2022
62574bd
Formatting.
tolo Sep 27, 2022
850f41a
Removed NestedNavigationShellRoute and replaced it with new field `ne…
tolo Sep 27, 2022
1c04588
Rebased onto upstream/main.
tolo Sep 27, 2022
1db6bba
Fixed typos.
tolo Sep 27, 2022
6028c90
Updated documentation of property navigatorKey on ShellRoute.
tolo Sep 28, 2022
5f2e995
Added another unit test for ShellRoute with nestedNavigationBuilder.
tolo Sep 28, 2022
461efd9
Updated example to use nested ShellRoutes instead of creating nested …
tolo Sep 28, 2022
0315e1a
Refactored support for nested stateful navigation - introduced new ro…
tolo Sep 30, 2022
510ec34
Some renaming.
tolo Sep 30, 2022
e82647a
Changed the way currentLocation is calculated since it currently does…
tolo Sep 30, 2022
e38fa32
Minor cleanup and refactoring.
tolo Sep 30, 2022
f38b9bf
Renamed StackedNavigationScaffold to StackedNavigationShell.
tolo Sep 30, 2022
89f1dd7
Added more tests for PartitionedShellRoute.
tolo Sep 30, 2022
3a00a54
Added more detail
tolo Sep 30, 2022
b0a6264
Fixed analyzer issue and code style issue.
tolo Sep 30, 2022
b729d64
Merge branch 'main' of github.com:flutter/packages into nested-persis…
johnpryan Sep 30, 2022
3b3909f
Fix test
johnpryan Sep 30, 2022
f0b2a1b
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Oct 2, 2022
eb6d4d3
Introduced the method `navigatorKeyForChildRoute` on ShellRouteBase t…
tolo Oct 2, 2022
016be76
Added a canPop test for PartitionedShellRoute (by replacing a duplica…
tolo Oct 2, 2022
4ae26d7
Updated implementation of popRoute be in sync with canPop.
tolo Oct 2, 2022
4a9889a
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Oct 3, 2022
1f3f01a
Updated documentation of PartitionedShellRoute with examples.
tolo Oct 3, 2022
3b38641
Updated documentation for builder and pageBuilder fields of ShellRout…
tolo Oct 3, 2022
d701ab5
Fixed documentation typos and minor refactoring (renaming).
tolo Oct 3, 2022
bb6240d
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Oct 3, 2022
245d47b
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Oct 4, 2022
bda571b
Refactored PartitionedShellRoute and renamed to StatefulShellRoute.
tolo Oct 7, 2022
da1ea0b
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Oct 7, 2022
59c19e7
Some refactoring (mostly naming and code readability).
tolo Oct 10, 2022
723de76
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Oct 10, 2022
4c0a91d
Fixed CI analyzer issue.
tolo Oct 10, 2022
7556965
Removed animation support from StatefulNavigationShell and refactored…
tolo Oct 11, 2022
ee9bde9
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Oct 11, 2022
e9a7029
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Oct 13, 2022
59a6b05
Updated changelog (replaced PartitionedShellRoute with StatefulShellR…
tolo Oct 13, 2022
06ab1e9
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Oct 14, 2022
1b877c8
Implemented equality in StatefulShellRouteState and ShellRouteBranchS…
tolo Oct 22, 2022
e542a05
Documentation updates.
tolo Oct 23, 2022
2215a51
Removed field navigatorKeys from StatefulShellRoute and fixed issue w…
tolo Oct 25, 2022
b180653
Removed the use of top GoRouterState as a way of getting the current …
tolo Oct 25, 2022
8fdfb82
Updated example to use the default constructors of StatefulShellRoute…
tolo Oct 25, 2022
9240ea4
Added check when pushing a new route to ensure you cannot push a rout…
tolo Oct 25, 2022
93bce8e
Minor renaming.
tolo Oct 25, 2022
20dc0c6
Added restorationScopeId to ShellRouteBranch and ShellRoute.
tolo Oct 25, 2022
376e80f
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Oct 25, 2022
2b2ff91
Added support for maintaining any extra navigation object passed to t…
tolo Oct 27, 2022
5c9fe04
Moved NEXT info 5.2.0 in changelog
tolo Oct 28, 2022
81e1296
Added assertion in RouteConfiguration for field defaultLocation of Sh…
tolo Oct 28, 2022
59e3b66
Added field preloadBranches to StatefulShellRoute, to enable support …
tolo Oct 28, 2022
8636bf8
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Oct 28, 2022
1c509f1
Various updates from PR feedback:
tolo Oct 28, 2022
42c7b7d
Changed the way switching between route branches works - switching is…
tolo Oct 29, 2022
62e7fc1
Reverted restriction around pushing sub-routes of a StatefulShellRoute.
tolo Oct 30, 2022
9a7069a
Doc fixes/updates for StatefulShellRoute.
tolo Oct 30, 2022
ae48ede
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Oct 30, 2022
141fdc1
Added handling of redirection when switching and preloading route bra…
tolo Nov 4, 2022
b6b289f
Reintroduced validation of defaultLocation of StatefulShellRoute (in …
tolo Nov 4, 2022
4d05d99
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Nov 4, 2022
d4edd47
Removed replaceMatchList in GoRouterDelegate (using setNewRoutePath i…
tolo Nov 4, 2022
7b9de47
Added additional test for redirection with StatefulShellRoute.
tolo Nov 4, 2022
703815c
Updated ShellRouteBranch to accept list of routes instead of only a s…
tolo Nov 9, 2022
9f88928
Added support for resetting StatefulShellRouteState.
tolo Nov 9, 2022
5ca533d
Renamed and changed signature of the navigator getters of StatefulShe…
tolo Nov 9, 2022
f5f0ecb
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Nov 9, 2022
4a2eac3
Added temporary workaround due to duplication of encodedParams of Rou…
tolo Nov 18, 2022
fc7bd54
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Nov 18, 2022
a65f9df
Refactoring of StatefulShellRoute to support dynamic branches, as wel…
tolo Nov 29, 2022
816acb2
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Nov 29, 2022
ee2a845
Introduced an internal branch Navigator proxy widget to make the API …
tolo Nov 30, 2022
89b82c5
Renamed StatefulShellRoute example file to stateful_shell_route.dart
tolo Nov 30, 2022
90b9d62
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Nov 30, 2022
7392264
Reduced unnecessary rebuilds of child Widgets of StatefulShellRoute, …
tolo Dec 1, 2022
c0253f6
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Dec 1, 2022
2c4afa1
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Dec 2, 2022
845c052
Minor refactoring - moved StatefulShellBranchResolver to route.dart.
tolo Dec 2, 2022
193a267
Fixed issue in StatefulShellBranch.isBranchFor (accidental use of inc…
tolo Dec 8, 2022
37c4969
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Dec 8, 2022
c562482
Reverted workaround regarding pop.
tolo Dec 8, 2022
38b5772
Equality fix in UnmodifiableRouteMatchList.
tolo Dec 8, 2022
db22bac
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Dec 8, 2022
d8d1641
Corrected invalid sample file names.
tolo Dec 13, 2022
4c4b7b0
Additional rebuild improvement.
tolo Dec 13, 2022
f08f548
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Dec 13, 2022
6f1b047
Minor documentation fix.
tolo Dec 14, 2022
07ee030
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Dec 14, 2022
9ffff5c
Removed AppRouterProvider from sample code.
tolo Dec 15, 2022
e9d40ee
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Dec 15, 2022
0ea48cb
Update packages/go_router/CHANGELOG.md
tolo Dec 21, 2022
4abcaa9
Update packages/go_router/CHANGELOG.md
tolo Dec 21, 2022
ce23558
Update packages/go_router/CHANGELOG.md
tolo Dec 21, 2022
351ceb2
Update packages/go_router/lib/src/route.dart
tolo Dec 21, 2022
4cb0f1e
Partially reverted the StatefulShellRoute API back to the previous so…
tolo Jan 5, 2023
e6a4f71
Documentation updates and some renaming.
tolo Jan 5, 2023
873bf34
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Jan 5, 2023
5b668f8
Fix for error in _preloadShellBranchNavigator due to recent changes i…
tolo Jan 5, 2023
565c3cd
Updated _routeMatchLookUp to handle reused/cached Navigators.
tolo Jan 19, 2023
5ee1a8f
Added support for resetting state for single branch (resetBranch).
tolo Jan 19, 2023
358551f
Added examples of pushing modal routes above the stateful shell.
tolo Jan 19, 2023
f9a2608
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Jan 19, 2023
87211aa
Alternative StatefulShellRoute implementation, were either a builder …
tolo Feb 7, 2023
257a272
Extracted construction of StatefulNavigationShell and Navigators out …
tolo Feb 16, 2023
08148e5
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Feb 16, 2023
c18941f
Added NavigatorObserver support to StatefulShellRoute.
tolo Feb 16, 2023
b1ce762
Refactored the builder methods of the shell route classes to improve …
tolo Feb 16, 2023
75e43d0
Various refactoring.
tolo Feb 17, 2023
9f54b4e
Minor renaming.
tolo Feb 17, 2023
1226f44
Updated equals method in GoRouterState to properly compare Map fields.
tolo Feb 19, 2023
881be86
Updated handling of RouteMatch lookup for pages/routes (replaced Expa…
tolo Feb 19, 2023
6bbbd29
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Feb 19, 2023
fd5412f
Add type annotation to listEquals
tolo Feb 23, 2023
a5234a6
Moved RouteNavigatorBuilder into builder.dart and made private.
tolo Feb 26, 2023
b9428cb
Moved StatefulNavigationShell and support classes into route.dart and…
tolo Feb 26, 2023
ee047c8
Refactoring of StatefulShellRoute and related classes to simplify bui…
tolo Mar 8, 2023
ddc71f0
Re-introduced proper validation of parent Navigator keys for routes i…
tolo Mar 8, 2023
5041bea
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Mar 8, 2023
01cce04
Updated constructors in sample code to use super parameters.
tolo Mar 8, 2023
9315373
Removed preload support.
tolo Mar 10, 2023
89341ef
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Mar 10, 2023
2c298cd
Refactored state management for StatefulShellRoute.
tolo Mar 13, 2023
4c22b53
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Mar 13, 2023
a7d419f
Moved branch state management back into StatefulShellRoute and simpli…
tolo Mar 31, 2023
7285788
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Mar 31, 2023
9983887
Renamed StatefulShellRoute to StackedShellRoute
tolo Apr 6, 2023
ad43837
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Apr 6, 2023
3a83007
Merge remote-tracking branch 'upstream/main' into nested-persistent-n…
tolo Apr 6, 2023
ec6722c
Update packages/go_router/lib/src/route.dart
tolo Apr 15, 2023
9bb0da9
Update packages/go_router/lib/src/route.dart
tolo Apr 15, 2023
a1c7a8f
Update packages/go_router/lib/src/route.dart
tolo Apr 15, 2023
477b47c
Removed StackedShellRouteState and moved functionality into StackedNa…
tolo Apr 20, 2023
7f25f0c
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Apr 20, 2023
6f35636
Doc updates - removed/replaced references to StackedShellRouteState.
tolo Apr 20, 2023
bb5c08f
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo Apr 28, 2023
16c095c
Refactoring due to review feedback.
tolo Apr 29, 2023
a18a5a5
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo May 1, 2023
abbd01b
Removed matchListEquals from RouteMatchList and replaced with the now…
tolo May 1, 2023
0f36623
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo May 1, 2023
316cf8c
Removed obsolete copy method from RouteMatchList.
tolo May 4, 2023
79a0c63
Updated StatefulNavigationShell to only save the part of the RouteMat…
tolo May 4, 2023
3696448
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo May 4, 2023
763b136
Minor sample code refactoring (documentation and renaming).
tolo May 8, 2023
2f48831
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo May 8, 2023
709ee7a
Apply suggestions from code review
tolo May 10, 2023
bb7fd9e
Implemented review feedback
tolo May 10, 2023
9eaf1af
Some additional cleanup
tolo May 10, 2023
527a806
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo May 10, 2023
86a72e1
Merge branch 'main' into nested-persistent-navigation
johnpryan May 17, 2023
57b761f
Apply suggestions from code review
tolo May 18, 2023
85fa0b6
Apply suggestions from code review.
tolo May 18, 2023
d75c5e2
Reintroduced resetLocation parameter to goBranch.
tolo May 18, 2023
bd1c018
Merge remote-tracking branch 'upstream/main' into nested-persistent-n…
tolo May 18, 2023
c13cd71
Renamed parameter resetLocation in goBranch to initialLocation.
tolo May 19, 2023
c7b1295
Fixed future deprecation warning workaround
tolo May 19, 2023
0f842ee
Merge remote-tracking branch 'upstream/main' into nested-persistent-n…
tolo May 19, 2023
80c396f
Merge branch 'main' into nested-persistent-navigation
chunhtai May 19, 2023
04b549a
Merge branch 'main' into nested-persistent-navigation
johnpryan May 22, 2023
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
Prev Previous commit
Next Next commit
Some additional cleanup
  • Loading branch information
tolo committed May 10, 2023
commit 9eaf1af15ebf9ccefcfc1e6d343c3ce03fa5c918
4 changes: 2 additions & 2 deletions packages/go_router/lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class RouteBuilder {
/// changes.
final List<NavigatorObserver> observers;

final GoRouterStateRegistry _registry = GoRouterStateRegistry();

/// A callback called when a `route` produced by `match` is about to be popped
/// with the `result`.
///
Expand All @@ -68,8 +70,6 @@ class RouteBuilder {
/// If this method returns false, this builder aborts the pop.
final PopPageWithRouteMatchCallback onPopPageWithRouteMatch;

final GoRouterStateRegistry _registry = GoRouterStateRegistry();

/// Caches a HeroController for the nested Navigator, which solves cases where the
/// Hero Widget animation stops working when navigating.
// TODO(chunhtai): Remove _goHeroCache once below issue is fixed:
Expand Down
4 changes: 2 additions & 2 deletions packages/go_router/lib/src/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ class ShellRoute extends ShellRouteBase {
/// when switching active branch.
///
/// For a default implementation of [navigatorContainerBuilder], consider using
/// [StackedShellRoute].
/// [StatefulShellRoute].
///
/// Below is a simple example of how a router configuration with
/// StatefulShellRoute could be achieved. In this example, a
Expand Down Expand Up @@ -692,7 +692,7 @@ class ShellRoute extends ShellRouteBase {
/// ```
///
/// See [Stateful Nested Navigation](https://github.com/flutter/packages/blob/main/packages/go_router/example/lib/stacked_shell_route.dart)
/// for a complete runnable example using StatefulShellRoute and StackedShellRoute.
/// for a complete runnable example using StatefulShellRoute and StatefulShellRoute.
class StatefulShellRoute extends ShellRouteBase {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does hot reloading reset the state?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just tried running the sample code in macOS and iOS, and hot reload seemed to work as expected. Which environment did you test on?

Copy link
Contributor

@johnpryan johnpryan May 18, 2023

Choose a reason for hiding this comment

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

I tested with this app on iOS and Desktop:

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

void main() {
  runApp(MyApp());
}

class Foo extends StatelessWidget {
  const Foo({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const Placeholder();
  }
}


///
class MyApp extends StatelessWidget {
  ///
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerConfig: GoRouter(
        routes: <RouteBase>[
          StatefulShellRoute.indexedStack(
            branches: [
              StatefulShellBranch(
                routes: [
                  GoRoute(
                    path: '/',
                    pageBuilder: (BuildContext context, GoRouterState state) {
                      return FadeTransitionPage(key: state.pageKey, child: HomeScreen());
                    },
                  ),
                ],
              ),
              StatefulShellBranch(
                routes: [
                  GoRoute(
                    path: '/work',
                    pageBuilder: (BuildContext context, GoRouterState state) {
                      return FadeTransitionPage(key: state.pageKey, child: WorkScreen());
                    },
                  ),
                ],
              ),
            ],
            builder: (BuildContext context, GoRouterState state,
                StatefulNavigationShell navigationShell) {
              return AppScaffold(
                shell: navigationShell,
              );
            },
          ),
        ],
      ),
    );
  }
}

///
class AppScaffold extends StatelessWidget {
  final StatefulNavigationShell shell;

  ///
  const AppScaffold({super.key, required this.shell});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: shell,
      bottomNavigationBar: BottomNavigationBar(
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'),
          BottomNavigationBarItem(icon: Icon(Icons.work), label: 'Work'),
        ],
        currentIndex: shell.currentIndex,
        onTap: (int index) => _onTap(context, index),
      ),
    );
  }

  void _onTap(BuildContext context, int index) {
    shell.goBranch(index);
  }
}

///
class HomeScreen extends StatefulWidget {
  ///
  const HomeScreen({super.key});

  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  @override
  Widget build(BuildContext context) {
    return const Scaffold(
      body: Center(
        child: Text('Home'),
      ),
    );
  }
}

///
class WorkScreen extends StatefulWidget {
  ///
  const WorkScreen({super.key});

  @override
  State<WorkScreen> createState() => _WorkScreenState();
}

class _WorkScreenState extends State<WorkScreen> {
  int count = 0;
  final Stream<dynamic> _stream = Stream.periodic(Duration(seconds: 1));
  late final StreamSubscription<dynamic> _subscription;

  ///
  void initState() {
    super.initState();
    _subscription = _stream.listen((_) {
      setState(() {
        count++;
      });
    });
  }

  ///
  void dispose() {
    _subscription.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Text('Count!!! $count'),
      ),
    );
  }
}

/// A page that fades in an out.
class FadeTransitionPage extends CustomTransitionPage<void> {
  /// Creates a [FadeTransitionPage].
  FadeTransitionPage({
    required LocalKey super.key,
    required super.child,
  }) : super(
      transitionsBuilder: (BuildContext context,
          Animation<double> animation,
          Animation<double> secondaryAnimation,
          Widget child) =>
          FadeTransition(
            opacity: animation.drive(_curveTween),
            child: child,
          ));

  static final CurveTween _curveTween = CurveTween(curve: Curves.easeIn);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'll have a look at your code and see what's going on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, so the main issue with this code I guess is that the GoRouter is recreated every time MyApp is rebuilt. Among other things this means that new and unique Navigators will be created on each hot reload, thus effectively resetting state.

As I've understood it, the intended way to use GoRouter is by creating a single instance only once, and then passing that instance to MaterialApp.router, like the code below (and like is done in all the sample code and documentation).
I've certainly run into issues myself (with other routes / ShellRoute) when not doing so.

final _router = GoRouter(
  routes: [
    ...
  ],
);

Widget build(BuildContext context) {
  return MaterialApp.router(
    routerConfig: _router,
  );
}

Copy link
Contributor

@johnpryan johnpryan May 18, 2023

Choose a reason for hiding this comment

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

I suspect this is because StatefulNavigationShell doesn't use a Key. I don't think users should need to define GoRouter as a field on the library, but without a Key, the framework won't know which State object to use when the app rebuilds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that possibly this shouldn't be a requirement, but I'm wondering if go_router is built to support this right now?

Anyway, to make this example work, you would need to use fixed navigatorKeys for both GoRouter and each of the branches. And you're probably (partially) right about the key for StatefulNavigationShell - a GlobalKey is actually used for that Widget though, the problem is that a new key is created each time StatefulShellRoute is instantiated (the shell route holds the key). I tried making it possible to pass this key in the constructor to StatefulShellRoute, but I ended up with new problems with "GlobalKey used by multiple widgets" errors.

/// Constructs a [StatefulShellRoute] from a list of [StatefulShellBranch]es,
/// each representing a separate nested navigation tree (branch).
Expand Down
16 changes: 8 additions & 8 deletions packages/go_router/test/configuration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void main() {
});

test(
'throws when StackedShellRoute sub-route uses incorrect parentNavigatorKey',
'throws when StatefulShellRoute sub-route uses incorrect parentNavigatorKey',
() {
final GlobalKey<NavigatorState> root =
GlobalKey<NavigatorState>(debugLabel: 'root');
Expand Down Expand Up @@ -125,7 +125,7 @@ void main() {
});

test(
'does not throw when StackedShellRoute sub-route uses correct parentNavigatorKeys',
'does not throw when StatefulShellRoute sub-route uses correct parentNavigatorKeys',
() {
final GlobalKey<NavigatorState> root =
GlobalKey<NavigatorState>(debugLabel: 'root');
Expand Down Expand Up @@ -160,7 +160,7 @@ void main() {
});

test(
'throws when a sub-route of StackedShellRoute has a parentNavigatorKey',
'throws when a sub-route of StatefulShellRoute has a parentNavigatorKey',
() {
final GlobalKey<NavigatorState> root =
GlobalKey<NavigatorState>(debugLabel: 'root');
Expand Down Expand Up @@ -205,7 +205,7 @@ void main() {
);
});

test('throws when StackedShellRoute has duplicate navigator keys', () {
test('throws when StatefulShellRoute has duplicate navigator keys', () {
final GlobalKey<NavigatorState> root =
GlobalKey<NavigatorState>(debugLabel: 'root');
final GlobalKey<NavigatorState> keyA =
Expand Down Expand Up @@ -236,7 +236,7 @@ void main() {
});

test(
'throws when a child of StackedShellRoute has an incorrect '
'throws when a child of StatefulShellRoute has an incorrect '
'parentNavigatorKey', () {
final GlobalKey<NavigatorState> root =
GlobalKey<NavigatorState>(debugLabel: 'root');
Expand Down Expand Up @@ -277,7 +277,7 @@ void main() {
});

test(
'throws when a branch of a StackedShellRoute has an incorrect '
'throws when a branch of a StatefulShellRoute has an incorrect '
'initialLocation', () {
final GlobalKey<NavigatorState> root =
GlobalKey<NavigatorState>(debugLabel: 'root');
Expand Down Expand Up @@ -323,7 +323,7 @@ void main() {
});

test(
'throws when a branch of a StackedShellRoute has a initialLocation '
'throws when a branch of a StatefulShellRoute has a initialLocation '
'that is not a descendant of the same branch', () {
final GlobalKey<NavigatorState> root =
GlobalKey<NavigatorState>(debugLabel: 'root');
Expand Down Expand Up @@ -378,7 +378,7 @@ void main() {
});

test(
'does not throw when a branch of a StackedShellRoute has correctly '
'does not throw when a branch of a StatefulShellRoute has correctly '
'configured initialLocations', () {
final GlobalKey<NavigatorState> root =
GlobalKey<NavigatorState>(debugLabel: 'root');
Expand Down
30 changes: 15 additions & 15 deletions packages/go_router/test/go_router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2504,7 +2504,7 @@ void main() {
expect(imperativeRouteMatch.matches.pathParameters['pid'], pid);
});

testWidgets('StackedShellRoute supports nested routes with params',
testWidgets('StatefulShellRoute supports nested routes with params',
(WidgetTester tester) async {
StatefulNavigationShell? routeState;
final List<RouteBase> routes = <RouteBase>[
Expand Down Expand Up @@ -3075,7 +3075,7 @@ void main() {
expect(find.text('Screen C'), findsNothing);
});

testWidgets('Builds StackedShellRoute', (WidgetTester tester) async {
testWidgets('Builds StatefulShellRoute', (WidgetTester tester) async {
final GlobalKey<NavigatorState> rootNavigatorKey =
GlobalKey<NavigatorState>();

Expand Down Expand Up @@ -3114,7 +3114,7 @@ void main() {
expect(find.text('Screen B'), findsOneWidget);
});

testWidgets('Builds StackedShellRoute as a sub-route',
testWidgets('Builds StatefulShellRoute as a sub-route',
(WidgetTester tester) async {
final GlobalKey<NavigatorState> rootNavigatorKey =
GlobalKey<NavigatorState>();
Expand Down Expand Up @@ -3162,7 +3162,7 @@ void main() {
});

testWidgets(
'Navigation with goBranch is correctly handled in StackedShellRoute',
'Navigation with goBranch is correctly handled in StatefulShellRoute',
(WidgetTester tester) async {
final GlobalKey<NavigatorState> rootNavigatorKey =
GlobalKey<NavigatorState>();
Expand Down Expand Up @@ -3254,7 +3254,7 @@ void main() {
});

testWidgets(
'Navigates to correct nested navigation tree in StackedShellRoute '
'Navigates to correct nested navigation tree in StatefulShellRoute '
'and maintains state', (WidgetTester tester) async {
final GlobalKey<NavigatorState> rootNavigatorKey =
GlobalKey<NavigatorState>();
Expand Down Expand Up @@ -3324,7 +3324,7 @@ void main() {
expect(statefulWidgetKey.currentState?.counter, equals(0));
});

testWidgets('Maintains state for nested StackedShellRoute',
testWidgets('Maintains state for nested StatefulShellRoute',
(WidgetTester tester) async {
final GlobalKey<NavigatorState> rootNavigatorKey =
GlobalKey<NavigatorState>();
Expand Down Expand Up @@ -3421,7 +3421,7 @@ void main() {
});

testWidgets(
'Pops from the correct Navigator in a StackedShellRoute when the '
'Pops from the correct Navigator in a StatefulShellRoute when the '
'Android back button is pressed', (WidgetTester tester) async {
final GlobalKey<NavigatorState> rootNavigatorKey =
GlobalKey<NavigatorState>();
Expand Down Expand Up @@ -3511,7 +3511,7 @@ void main() {

testWidgets(
'Maintains extra navigation information when navigating '
'between branches in StackedShellRoute', (WidgetTester tester) async {
'between branches in StatefulShellRoute', (WidgetTester tester) async {
final GlobalKey<NavigatorState> rootNavigatorKey =
GlobalKey<NavigatorState>();
StatefulNavigationShell? routeState;
Expand Down Expand Up @@ -3564,7 +3564,7 @@ void main() {

testWidgets(
'Pushed non-descendant routes are correctly restored when '
'navigating between branches in StackedShellRoute',
'navigating between branches in StatefulShellRoute',
(WidgetTester tester) async {
final GlobalKey<NavigatorState> rootNavigatorKey =
GlobalKey<NavigatorState>();
Expand Down Expand Up @@ -3629,7 +3629,7 @@ void main() {

testWidgets(
'Redirects are correctly handled when switching branch in a '
'StackedShellRoute', (WidgetTester tester) async {
'StatefulShellRoute', (WidgetTester tester) async {
final GlobalKey<NavigatorState> rootNavigatorKey =
GlobalKey<NavigatorState>();
StatefulNavigationShell? routeState;
Expand Down Expand Up @@ -3724,7 +3724,7 @@ void main() {
});

testWidgets(
'Pushed top-level route is correctly handled by StackedShellRoute',
'Pushed top-level route is correctly handled by StatefulShellRoute',
(WidgetTester tester) async {
final GlobalKey<NavigatorState> rootNavigatorKey =
GlobalKey<NavigatorState>();
Expand Down Expand Up @@ -3954,7 +3954,7 @@ void main() {
);

testWidgets(
'It checks if StackedShellRoute navigators can pop',
'It checks if StatefulShellRoute navigators can pop',
(WidgetTester tester) async {
final GlobalKey<NavigatorState> rootNavigatorKey =
GlobalKey<NavigatorState>();
Expand Down Expand Up @@ -4015,7 +4015,7 @@ void main() {
expect(find.text('Screen B detail', skipOffstage: false),
findsOneWidget);
expect(router.canPop(), true);
// Verify that it is actually the StackedShellRoute that reports
// Verify that it is actually the StatefulShellRoute that reports
// canPop = true
expect(rootNavigatorKey.currentState?.canPop(), false);
},
Expand Down Expand Up @@ -4370,7 +4370,7 @@ void main() {
expect(statefulWidgetKeyA.currentState?.counter, equals(1));
});

testWidgets('Restores state of branches in StackedShellRoute correctly',
testWidgets('Restores state of branches in StatefulShellRoute correctly',
(WidgetTester tester) async {
final GlobalKey<NavigatorState> rootNavigatorKey =
GlobalKey<NavigatorState>();
Expand Down Expand Up @@ -4503,7 +4503,7 @@ void main() {
});

testWidgets(
'Restores state of imperative routes in StackedShellRoute correctly',
'Restores state of imperative routes in StatefulShellRoute correctly',
(WidgetTester tester) async {
final GlobalKey<NavigatorState> rootNavigatorKey =
GlobalKey<NavigatorState>();
Expand Down