Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[go_router] Nested stateful navigation with ShellRoute #2650

Closed
wants to merge 159 commits into from
Closed
Show file tree
Hide file tree
Changes from 17 commits
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
7 changes: 7 additions & 0 deletions packages/go_router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 5.1.0

- Introduced a new shell route class called `PartitionedShellRoute`, to support using separate
navigators for child routes as well as preserving state in each navigation tree
(flutter/flutter#99124). Also introduced the supporting widget class `StackedNavigationShell`,
which facilitates using an `IndexStack` to manage multiple parallel navigation trees.

## 5.0.3

- Changes examples to use the routerConfig API
Expand Down
6 changes: 6 additions & 0 deletions packages/go_router/example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ An example to demonstrate how to use redirect to handle a synchronous sign-in fl
## [Asynchronous Redirection](https://github.com/flutter/packages/blob/main/packages/go_router/example/lib/async_redirection.dart)
`flutter run lib/async_redirection.dart`

An example to demonstrate how to use a `Shell Route` to create stateful nested navigation, with a
`BottomNavigationBar`.

## [Stateful Nested Navigation](https://github.com/flutter/packages/blob/main/packages/go_router/example/lib/stateful_nested_navigation.dart)
`flutter run lib/stateful_nested_navigation.dart`

An example to demonstrate how to use handle a sign-in flow with a stream authentication service.

## [Books app](https://github.com/flutter/packages/blob/main/packages/go_router/example/lib/books)
Expand Down
295 changes: 295 additions & 0 deletions packages/go_router/example/lib/stateful_nested_navigation.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

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

final GlobalKey<NavigatorState> _sectionANavigatorKey =
GlobalKey<NavigatorState>(debugLabel: 'sectionANav');
final GlobalKey<NavigatorState> _sectionBNavigatorKey =
GlobalKey<NavigatorState>(debugLabel: 'sectionBNav');

// This example demonstrates how to setup nested navigation using a
// BottomNavigationBar, where each tab uses its own persistent navigator, i.e.
// navigation state is maintained separately for each tab. This setup also
// enables deep linking into nested pages.
//
// This example demonstrates how to display routes within a ShellRoute using a
// `nestedNavigationBuilder`. Navigators for the tabs ('Section A' and
// 'Section B') are created via nested ShellRoutes. Note that no navigator will
// be created by the "top" ShellRoute. This example is similar to the ShellRoute
// example, but differs in that it is able to maintain the navigation state of
// each tab.

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

/// An example demonstrating how to use nested navigators
class NestedTabNavigationExampleApp extends StatelessWidget {
/// Creates a NestedTabNavigationExampleApp
NestedTabNavigationExampleApp({Key? key}) : super(key: key);

static final List<ScaffoldWithNavBarTabItem> _tabs =
<ScaffoldWithNavBarTabItem>[
ScaffoldWithNavBarTabItem(
navigationItem: StackedNavigationItem(
rootRoutePath: '/a', navigatorKey: _sectionANavigatorKey),
icon: const Icon(Icons.home),
label: 'Section A'),
ScaffoldWithNavBarTabItem(
navigationItem: StackedNavigationItem(
rootRoutePath: '/b', navigatorKey: _sectionBNavigatorKey),
icon: const Icon(Icons.settings),
label: 'Section B',
),
];

final GoRouter _router = GoRouter(
initialLocation: '/a',
routes: <RouteBase>[
/// Custom top shell route - wraps the below routes in a scaffold with
/// a bottom tab navigator (ScaffoldWithNavBar). Each tab will use its own
/// Navigator, provided by MultiPathShellRoute.
PartitionedShellRoute.stackedNavigation(
stackItems: _tabs
.map((ScaffoldWithNavBarTabItem e) => e.navigationItem)
.toList(),
scaffoldBuilder: (BuildContext context, int currentIndex,
List<StackedNavigationItemState> itemsState, Widget scaffoldBody) {
return ScaffoldWithNavBar(
tabs: _tabs,
currentIndex: currentIndex,
itemsState: itemsState,
body: scaffoldBody);
},

/// A transition builder is optional, only included here for
/// demonstration purposes.
transitionBuilder:
(BuildContext context, Animation<double> animation, Widget child) =>
FadeTransition(opacity: animation, child: child),
routes: <GoRoute>[
/// The screen to display as the root in the first tab of the bottom
/// navigation bar. Note that the root route must specify the
/// `parentNavigatorKey`
GoRoute(
parentNavigatorKey: _sectionANavigatorKey,
path: '/a',
builder: (BuildContext context, GoRouterState state) =>
const RootScreen(label: 'A', detailsPath: '/a/details'),
routes: <RouteBase>[
/// The details screen to display stacked on navigator of the
/// first tab. This will cover screen A but not the application
/// shell (bottom navigation bar).
GoRoute(
path: 'details',
builder: (BuildContext context, GoRouterState state) =>
const DetailsScreen(label: 'A'),
),
],
),

/// The screen to display as the root in the second tab of the bottom
/// navigation bar.
GoRoute(
parentNavigatorKey: _sectionBNavigatorKey,
path: '/b',
builder: (BuildContext context, GoRouterState state) =>
const RootScreen(
label: 'B',
detailsPath: '/b/details/1',
detailsPath2: '/b/details/2'),
routes: <RouteBase>[
/// The details screen to display stacked on navigator of the
/// second tab. This will cover screen B but not the application
/// shell (bottom navigation bar).
GoRoute(
path: 'details/:param',
builder: (BuildContext context, GoRouterState state) =>
DetailsScreen(label: 'B', param: state.params['param']),
),
],
),
],
),
],
);

@override
Widget build(BuildContext context) {
return MaterialApp.router(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
routerConfig: _router,
);
}
}

/// Representation of a tab item in a [ScaffoldWithNavBar]
class ScaffoldWithNavBarTabItem extends BottomNavigationBarItem {
/// Constructs an [ScaffoldWithNavBarTabItem].
const ScaffoldWithNavBarTabItem(
{required this.navigationItem, required Widget icon, String? label})
: super(icon: icon, label: label);

/// The [StackedNavigationItem]
final StackedNavigationItem navigationItem;

/// Gets the associated navigator key
GlobalKey<NavigatorState> get navigatorKey => navigationItem.navigatorKey;
}

/// Builds the "shell" for the app by building a Scaffold with a
/// BottomNavigationBar, where [child] is placed in the body of the Scaffold.
class ScaffoldWithNavBar extends StatelessWidget {
/// Constructs an [ScaffoldWithNavBar].
const ScaffoldWithNavBar({
required this.currentIndex,
required this.itemsState,
required this.body,
required this.tabs,
Key? key,
}) : super(key: key ?? const ValueKey<String>('ScaffoldWithNavBar'));

/// Currently active tab index
final int currentIndex;

/// Route state
final List<StackedNavigationItemState> itemsState;

/// Body, i.e. the index stack
final Widget body;

/// The tabs
final List<ScaffoldWithNavBarTabItem> tabs;

@override
Widget build(BuildContext context) {
return Scaffold(
body: body,
bottomNavigationBar: BottomNavigationBar(
items: tabs,
currentIndex: currentIndex,
onTap: (int tappedIndex) =>
_onItemTapped(context, itemsState[tappedIndex]),
),
);
}

void _onItemTapped(
BuildContext context, StackedNavigationItemState itemState) {
GoRouter.of(context).go(itemState.currentLocation);
tolo marked this conversation as resolved.
Show resolved Hide resolved
}
}
tolo marked this conversation as resolved.
Show resolved Hide resolved

/// Widget for the root/initial pages in the bottom navigation bar.
class RootScreen extends StatelessWidget {
/// Creates a RootScreen
const RootScreen(
{required this.label,
required this.detailsPath,
this.detailsPath2,
Key? key})
: super(key: key);

/// The label
final String label;

/// The path to the detail page
final String detailsPath;

/// The path to another detail page
final String? detailsPath2;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Tab root - $label'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text('Screen $label',
style: Theme.of(context).textTheme.titleLarge),
const Padding(padding: EdgeInsets.all(4)),
TextButton(
onPressed: () {
GoRouter.of(context).go(detailsPath);
},
child: const Text('View details'),
),
const Padding(padding: EdgeInsets.all(4)),
if (detailsPath2 != null)
TextButton(
onPressed: () {
GoRouter.of(context).go(detailsPath2!);
},
child: const Text('View more details'),
),
],
),
),
);
}
}

/// The details screen for either the A or B screen.
class DetailsScreen extends StatefulWidget {
/// Constructs a [DetailsScreen].
const DetailsScreen({
required this.label,
this.param,
Key? key,
}) : super(key: key);

/// The label to display in the center of the screen.
final String label;

/// Optional param
final String? param;

@override
State<StatefulWidget> createState() => DetailsScreenState();
}

/// The state for DetailsScreen
class DetailsScreenState extends State<DetailsScreen> {
int _counter = 0;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Details Screen - ${widget.label}'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
if (widget.param != null)
Text('Parameter: ${widget.param!}',
style: Theme.of(context).textTheme.titleLarge),
const Padding(padding: EdgeInsets.all(4)),
Text('Details for ${widget.label} - Counter: $_counter',
style: Theme.of(context).textTheme.titleLarge),
const Padding(padding: EdgeInsets.all(4)),
TextButton(
onPressed: () {
setState(() {
_counter++;
});
},
child: const Text('Increment counter'),
),
],
),
),
);
}
}
3 changes: 2 additions & 1 deletion packages/go_router/lib/go_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
library go_router;

export 'src/configuration.dart'
show GoRoute, GoRouterState, RouteBase, ShellRoute;
show GoRoute, GoRouterState, RouteBase, ShellRoute, PartitionedShellRoute;
export 'src/misc/extensions.dart';
export 'src/misc/inherited_router.dart';
export 'src/misc/stacked_navigation_shell.dart';
export 'src/pages/custom_transition_page.dart';
export 'src/platform.dart' show UrlPathStrategy;
export 'src/route_data.dart' show GoRouteData, TypedGoRoute;
Expand Down
Loading