Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
990c293
implemented helpers for StatefulShellRoute
hannah-hyj Jun 16, 2023
4918014
Merge branch 'main' into statefulshellroute
hannah-hyj Jun 16, 2023
c6bde6d
lint
hannah-hyj Jun 16, 2023
52ce037
Update route_data.dart
hannah-hyj Jun 16, 2023
b9c8080
lint
hannah-hyj Jun 16, 2023
9005a8c
Update route_data.dart
hannah-hyj Jun 16, 2023
8cf69b6
update
hannah-hyj Jun 26, 2023
5963020
resolve comments
hannah-hyj Jun 28, 2023
4f60cd6
1
hannah-hyj Jun 16, 2023
e4fc526
Revert "1"
hannah-hyj Jun 16, 2023
d328021
update
hannah-hyj Jun 26, 2023
bc19f53
update tests
hannah-hyj Jun 28, 2023
f827680
Merge branch 'main' of https://github.com/flutter/packages into build…
hannah-hyj Jul 9, 2023
6a09020
update
hannah-hyj Jul 10, 2023
bb6064b
bump version
hannah-hyj Jul 10, 2023
441eb78
Update route_config.dart
hannah-hyj Jul 10, 2023
8b4e2de
Update stateful_shell_route_test.dart
hannah-hyj Jul 10, 2023
a2ef5d2
Merge branch 'main' of https://github.com/flutter/packages into build…
hannah-hyj Jul 12, 2023
13865ac
update route_config
hannah-hyj Jul 12, 2023
e3d109d
Update route_config.dart
hannah-hyj Jul 19, 2023
51ae0a0
Merge branch 'main' of https://github.com/flutter/packages into build…
hannah-hyj Jul 19, 2023
bfd36ef
merge
hannah-hyj Jul 20, 2023
03c069b
resolve comments
hannah-hyj Jul 25, 2023
0da2339
update
hannah-hyj Jul 25, 2023
06c7e67
Update route_config.dart
hannah-hyj Jul 25, 2023
ecbc5f5
update
hannah-hyj Jul 31, 2023
9808f62
Merge branch 'main' of https://github.com/flutter/packages into build…
hannah-hyj Jul 31, 2023
6044e32
Update pubspec.yaml
hannah-hyj Jul 31, 2023
3c2ed3b
lint
hannah-hyj Jul 31, 2023
1e78def
Update stateful_shell_route_example.dart
hannah-hyj Jul 31, 2023
eecb67e
Update pubspec.yaml
hannah-hyj Jul 31, 2023
2e63519
Update pubspec.yaml
hannah-hyj Jul 31, 2023
cfb1de8
Update stateful_shell_route_example.dart
hannah-hyj Jul 31, 2023
7fa8523
Merge branch 'main' into builder-stateful
hannah-hyj Aug 2, 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
6 changes: 6 additions & 0 deletions packages/go_router_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.3.0

* Adds Support for StatefulShellRoute
* Updates the documentation to go_router v9.0.3
* Bumps go_router version in example folder to v9.0.3

## 2.2.1

* Cleans up go_router_builder code.
Expand Down
4 changes: 2 additions & 2 deletions packages/go_router_builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ To use `go_router_builder`, you need to have the following dependencies in
```yaml
dependencies:
# ...along with your other dependencies
go_router: ^7.0.0
go_router: ^9.0.3

dev_dependencies:
# ...along with your other dev-dependencies
build_runner: ^2.0.0
go_router_builder: ^2.0.0
go_router_builder: ^2.3.0
```

### Source code
Expand Down
26 changes: 13 additions & 13 deletions packages/go_router_builder/example/lib/all_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class BigIntRoute extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('BigIntRoute'),
onTap: () => go(context),
selected: GoRouter.of(context).location == location,
selected: GoRouterState.of(context).location == location,
);
}

Expand All @@ -84,7 +84,7 @@ class BoolRoute extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('BoolRoute'),
onTap: () => go(context),
selected: GoRouter.of(context).location == location,
selected: GoRouterState.of(context).location == location,
);
}

Expand All @@ -107,7 +107,7 @@ class DateTimeRoute extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('DateTimeRoute'),
onTap: () => go(context),
selected: GoRouter.of(context).location == location,
selected: GoRouterState.of(context).location == location,
);
}

Expand All @@ -133,7 +133,7 @@ class DoubleRoute extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('DoubleRoute'),
onTap: () => go(context),
selected: GoRouter.of(context).location == location,
selected: GoRouterState.of(context).location == location,
);
}

Expand All @@ -159,7 +159,7 @@ class IntRoute extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('IntRoute'),
onTap: () => go(context),
selected: GoRouter.of(context).location == location,
selected: GoRouterState.of(context).location == location,
);
}

Expand All @@ -185,7 +185,7 @@ class NumRoute extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('NumRoute'),
onTap: () => go(context),
selected: GoRouter.of(context).location == location,
selected: GoRouterState.of(context).location == location,
);
}

Expand All @@ -212,7 +212,7 @@ class EnumRoute extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('EnumRoute'),
onTap: () => go(context),
selected: GoRouter.of(context).location == location,
selected: GoRouterState.of(context).location == location,
);
}

Expand All @@ -239,7 +239,7 @@ class EnhancedEnumRoute extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('EnhancedEnumRoute'),
onTap: () => go(context),
selected: GoRouter.of(context).location == location,
selected: GoRouterState.of(context).location == location,
);
}

Expand All @@ -265,7 +265,7 @@ class StringRoute extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('StringRoute'),
onTap: () => go(context),
selected: GoRouter.of(context).location == location,
selected: GoRouterState.of(context).location == location,
);
}

Expand All @@ -288,7 +288,7 @@ class UriRoute extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('UriRoute'),
onTap: () => go(context),
selected: GoRouter.of(context).location == location,
selected: GoRouterState.of(context).location == location,
);
}

Expand Down Expand Up @@ -361,7 +361,7 @@ class IterableRoute extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('IterableRoute'),
onTap: () => go(context),
selected: GoRouter.of(context).location == location,
selected: GoRouterState.of(context).location == location,
);
}

Expand Down Expand Up @@ -430,7 +430,7 @@ class IterableRouteWithDefaultValues extends GoRouteData {
Widget drawerTile(BuildContext context) => ListTile(
title: const Text('IterableRouteWithDefaultValues'),
onTap: () => go(context),
selected: GoRouter.of(context).location == location,
selected: GoRouterState.of(context).location == location,
);
}

Expand Down Expand Up @@ -536,7 +536,7 @@ class BasePage<T> extends StatelessWidget {
Text(
'Query param with default value: $queryParamWithDefaultValue',
),
SelectableText(GoRouter.of(context).location),
SelectableText(GoRouterState.of(context).location),
],
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class MyShellRouteScreen extends StatelessWidget {
final Widget child;

int getCurrentIndex(BuildContext context) {
final String location = GoRouter.of(context).location;
final String location = GoRouterState.of(context).location;
if (location == '/bar') {
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MyShellRouteScreen extends StatelessWidget {
final Widget child;

int getCurrentIndex(BuildContext context) {
final String location = GoRouter.of(context).location;
final String location = GoRouterState.of(context).location;
if (location.startsWith('/users')) {
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
// 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.

// ignore_for_file: public_member_api_docs

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

part 'stateful_shell_route_example.g.dart';

final GlobalKey<NavigatorState> _sectionANavigatorKey =
GlobalKey<NavigatorState>(debugLabel: 'sectionANav');
void main() => runApp(App());

class App extends StatelessWidget {
App({super.key});

@override
Widget build(BuildContext context) => MaterialApp.router(
routerConfig: _router,
);

final GoRouter _router = GoRouter(
routes: $appRoutes,
initialLocation: '/detailsA',
);
}

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

@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: const Text('foo')),
);
}

@TypedStatefulShellRoute<MyShellRouteData>(
branches: <TypedStatefulShellBranch<StatefulShellBranchData>>[
TypedStatefulShellBranch<BranchAData>(
routes: <TypedRoute<RouteData>>[
TypedGoRoute<DetailsARouteData>(path: '/detailsA'),
],
),
TypedStatefulShellBranch<BranchBData>(
routes: <TypedRoute<RouteData>>[
TypedGoRoute<DetailsBRouteData>(path: '/detailsB'),
],
),
],
)
class MyShellRouteData extends StatefulShellRouteData {
const MyShellRouteData();

@override
Widget builder(
BuildContext context,
GoRouterState state,
StatefulNavigationShell navigationShell,
) {
return ScaffoldWithNavBar(navigationShell: navigationShell);
}
}

class BranchAData extends StatefulShellBranchData {
const BranchAData();
}

class BranchBData extends StatefulShellBranchData {
const BranchBData();

static final GlobalKey<NavigatorState> $navigatorKey = _sectionANavigatorKey;
}

class DetailsARouteData extends GoRouteData {
const DetailsARouteData();

@override
Widget build(BuildContext context, GoRouterState state) {
return const DetailsScreen(label: 'A');
}
}

class DetailsBRouteData extends GoRouteData {
const DetailsBRouteData();

@override
Widget build(BuildContext context, GoRouterState state) {
return const DetailsScreen(label: 'B');
}
}

/// 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.navigationShell,
Key? key,
}) : super(key: key ?? const ValueKey<String>('ScaffoldWithNavBar'));

/// The navigation shell and container for the branch Navigators.
final StatefulNavigationShell navigationShell;

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

void _onTap(BuildContext context, int index) {
navigationShell.goBranch(
index,
initialLocation: index == navigationShell.currentIndex,
);
}
}

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

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

/// Optional param
final String? param;

/// Optional extra object
final Object? extra;
@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: _build(context),
);
}

Widget _build(BuildContext context) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
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'),
),
const Padding(padding: EdgeInsets.all(8)),
if (widget.param != null)
Text('Parameter: ${widget.param!}',
style: Theme.of(context).textTheme.titleMedium),
const Padding(padding: EdgeInsets.all(8)),
if (widget.extra != null)
Text('Extra: ${widget.extra!}',
style: Theme.of(context).textTheme.titleMedium),
],
),
);
}
}
Loading