[go_router] Add support for preloading branches of StatefulShellRoute (revised solution) (#6467)
Adds support for preloading branches in a StatefulShellRoute. This functionality was initially part of an early implementation of flutter/packages#2650, however it was decided to implement this in a separate PR. The current implementation is a rewrite of the original implementation to better fit the final version of StatefulShellRoute (and go_router in general).
**NOTE**: this is a revised version of the initial solution (see flutter/packages#4251), containing a substantially simpler implementation made possible thanks to recent refactoring in go_router.
This fixes issue flutter/flutter#127804.
[various] Align Flutter and Dart SDK constraints (#3349)
As described in https://github.com/flutter/flutter/issues/121684, we currently have inconsistencies between Flutter SDK constraints and Dart SDK constraints; we have often updated only the former. This PR:
1. Adds CI enforcement via the repo tooling that the minimum versions are consistent.
2. Adds a new repo tooling command to update SDK constraints, to help mass-fix all the violations of the new enforcement in step 1 (and for future mass changes, such as when we update our test matrix and mass-drop support for versions that are no longe tested).
- In all cases, the looser constraint was updated to match the more restrictive constraint, such that there's no actual change in what Flutter version any package actually supports.
3. Runs dart fix --apply over all changed packages to automatically fix all of the analysis failures caused by step 2 suddenly making all of our packages able to use super parameters.
Fixes https://github.com/flutter/flutter/issues/121684
Fixes https://github.com/flutter/flutter/issues/121685
[various] Align Flutter and Dart SDK constraints (#3349)
As described in https://github.com/flutter/flutter/issues/121684, we currently have inconsistencies between Flutter SDK constraints and Dart SDK constraints; we have often updated only the former. This PR:
1. Adds CI enforcement via the repo tooling that the minimum versions are consistent.
2. Adds a new repo tooling command to update SDK constraints, to help mass-fix all the violations of the new enforcement in step 1 (and for future mass changes, such as when we update our test matrix and mass-drop support for versions that are no longe tested).
- In all cases, the looser constraint was updated to match the more restrictive constraint, such that there's no actual change in what Flutter version any package actually supports.
3. Runs dart fix --apply over all changed packages to automatically fix all of the analysis failures caused by step 2 suddenly making all of our packages able to use super parameters.
Fixes https://github.com/flutter/flutter/issues/121684
Fixes https://github.com/flutter/flutter/issues/121685
[go_router] Added missing implementation for the routerNeglect parameter in GoRouter (#7752)
The GoRouter constructor parameter routerNeglect currently has no effect. This PR provides an implementation for this parameter, in line with the original implementation, i.e. _"This will suppress history for all navigation made using go_router"_.
*List which issues are fixed by this PR. You must list at least one issue.*
* flutter/flutter#119398
[various] Align Flutter and Dart SDK constraints (#3349)
As described in https://github.com/flutter/flutter/issues/121684, we currently have inconsistencies between Flutter SDK constraints and Dart SDK constraints; we have often updated only the former. This PR:
1. Adds CI enforcement via the repo tooling that the minimum versions are consistent.
2. Adds a new repo tooling command to update SDK constraints, to help mass-fix all the violations of the new enforcement in step 1 (and for future mass changes, such as when we update our test matrix and mass-drop support for versions that are no longe tested).
- In all cases, the looser constraint was updated to match the more restrictive constraint, such that there's no actual change in what Flutter version any package actually supports.
3. Runs dart fix --apply over all changed packages to automatically fix all of the analysis failures caused by step 2 suddenly making all of our packages able to use super parameters.
Fixes https://github.com/flutter/flutter/issues/121684
Fixes https://github.com/flutter/flutter/issues/121685
[go_router] Nested stateful navigation with ShellRoute (#2650)
Added functionality for building route configuration with support for preserving state in nested navigators. This change introduces a new shell route class called StatefulShellRoute, that uses separate navigators for its child routes as well as preserving state in each navigation branch. This is convenient when for instance implementing a UI with a BottomNavigationBar, with a persistent navigation state for each tab (i.e. building a Navigator for each tab).
An example showcasing a UI with BottomNavigationBar and StatefulShellRoute has also been added ([stateful_shell_route.dart](https://github.com/tolo/flutter_packages/blob/nested-persistent-navigation/packages/go_router/example/lib/stateful_shell_route.dart)).
Other examples of using StatefulShellRoute are also available in these repositories:
* [stateful_books](https://github.com/tolo/stateful_books) - A fork of the Books example of go_router.
* [stateful_navbar](https://github.com/tolo/stateful_navbar) - A clone of the Flutter Material 3 Navigation Bar example.
<br/>
Below is a short example of how a StatefulShellRoute can be setup:
```dart
StatefulShellRoute(
/// Each separate stateful navigation tree (i.e. Navigator) is represented by
/// a StatefulShellBranch, which defines the routes that will be placed on that
/// Navigator. StatefulShellBranch also makes it possible to configure
/// things like an (optional) Navigator key, the default location (i.e. the
/// location the branch will be navigated to when loading it for the first time) etc.
branches: <StatefulShellBranch>[
StatefulShellBranch(navigatorKey: optionalNavigatorKey, routes: <RouteBase>[
GoRoute(
path: '/a',
builder: (BuildContext context, GoRouterState state) =>
const RootScreen(label: 'A'),
routes: <RouteBase>[
GoRoute(
path: 'details',
builder: (BuildContext context, GoRouterState state) =>
const DetailsScreen(label: 'A'),
),
],
),
]),
/// The default location of a branch will by default be the first of the
/// configured routes. To configure a different route, provide the
/// defaultLocation parameter.
StatefulShellBranch(defaultLocation: '/b/detail', routes: <RouteBase>[
GoRoute(
path: '/b',
builder: (BuildContext context, GoRouterState state) =>
const RootScreen(label: 'B'),
routes: <RouteBase>[
GoRoute(
path: 'details',
builder: (BuildContext context, GoRouterState state) =>
const DetailsScreen(label: 'B'),
),
],
),
]),
],
/// Like ShellRoute, the builder builds the navigation shell around the
/// sub-routes, but with StatefulShellRoute, this navigation shell is able to
/// maintain the state of the Navigators for each branch. The navigation shell
/// could for instance use a BottomNavigationBar or similar.
builder: (BuildContext context, StatefulShellRouteState state, Widget child) =>
ScaffoldWithNavBar(shellState: state, body: child),
)
```
This fixes issue flutter/flutter#99124.
It also (at least partially) addresses flutter/flutter#112267.