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_builder] Adds name parameter to TypedGoRoute and supports its generation. #3665

Merged
merged 26 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ded3b07
adds name parameter to TypedGoRoute
dancamdev Apr 8, 2023
5f467ce
adds tests
dancamdev Apr 8, 2023
8592c5e
updates changelog and pubspec
dancamdev Apr 8, 2023
c5a5a40
uses local go_router
dancamdev Apr 8, 2023
2fad775
Merge remote-tracking branch 'upstream/main' into feature/add-name
dancamdev Apr 8, 2023
cfab739
Merge remote-tracking branch 'upstream/main' into feature/add-name
dancamdev Apr 13, 2023
637b37f
Update CHANGELOG.md
dancamdev Apr 13, 2023
94c5f3e
Update route_data.dart
dancamdev Apr 13, 2023
6ddd3c3
Update pubspec.yaml
dancamdev Apr 13, 2023
4b3c9e6
Merge branch 'main' into feature/add-name
dancamdev Apr 14, 2023
82ff212
Merge branch 'feature/add-name' of https://github.com/App-and-Up/pack…
dancamdev Apr 14, 2023
c4067c6
Merge branch 'main' into feature/add-name
dancamdev Apr 26, 2023
8ea4eda
Merge branch 'main' into feature/add-name
dancamdev Apr 27, 2023
c2df8aa
fix go_router version from local to remote
Michele-x98 Apr 27, 2023
49668c2
fix tests with return value from push method
Michele-x98 Apr 27, 2023
c034451
fix version
Michele-x98 Apr 27, 2023
ec70a3e
fixes build_runner error
dancamdev Apr 28, 2023
5f8390d
Merge remote-tracking branch 'upstream/main' into feature/add-name
dancamdev Apr 28, 2023
77ed12c
Merge branch 'main' into feature/add-name
Michele-x98 Apr 28, 2023
e0d5f4a
Merge branch 'main' into feature/add-name
dancamdev May 2, 2023
bb770a3
Merge remote-tracking branch 'upstream/main' into feature/add-name
dancamdev May 8, 2023
1ddc59c
adds NamedEscapeRoute test
dancamdev May 8, 2023
27da54a
fixes lint errors
dancamdev May 8, 2023
0e7df68
Merge branch 'main' into feature/add-name
dancamdev May 8, 2023
d3ad5dc
Merge branch 'main' into feature/add-name
dancamdev May 9, 2023
ad97e1f
Merge branch 'main' into feature/add-name
dancamdev May 10, 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
3 changes: 3 additions & 0 deletions packages/go_router_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.0.1

* Supports name parameter for `TypedGoRoute`.
## 2.0.0

* Updates the documentation to go_router v7.0.0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class App extends StatelessWidget {

@TypedGoRoute<HomeRoute>(
path: '/',
name: 'Home',
routes: <TypedGoRoute<GoRouteData>>[
TypedGoRoute<FamilyRoute>(path: 'family/:familyId')
],
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions packages/go_router_builder/lib/src/route_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class InfoIterable extends IterableBase<String> {
class RouteConfig {
RouteConfig._(
this._path,
this._name,
this._routeDataClass,
this._parent,
this._key,
Expand Down Expand Up @@ -75,6 +76,7 @@ class RouteConfig {
final bool isShellRoute = type.element.name == 'TypedShellRoute';

String? path;
String? name;

if (!isShellRoute) {
final ConstantReader pathValue = reader.read('path');
Expand All @@ -85,6 +87,9 @@ class RouteConfig {
);
}
path = pathValue.stringValue;

final ConstantReader nameValue = reader.read('name');
name = nameValue.isNull ? null : nameValue.stringValue;
}

final DartType typeParamType = type.typeArguments.single;
Expand All @@ -104,6 +109,7 @@ class RouteConfig {

final RouteConfig value = RouteConfig._(
path ?? '',
name,
classElement,
parent,
_generateNavigatorKeyGetterCode(
Expand All @@ -121,6 +127,7 @@ class RouteConfig {

final List<RouteConfig> _children = <RouteConfig>[];
final String _path;
final String? _name;
final InterfaceElement _routeDataClass;
final RouteConfig? _parent;
final String? _key;
Expand Down Expand Up @@ -352,6 +359,7 @@ routes: [${_children.map((RouteConfig e) => '${e._routeDefinition()},').join()}]
return '''
GoRouteData.\$route(
path: ${escapeDartString(_path)},
${_name != null ? 'name: ${escapeDartString(_name!)},' : ''}
factory: $_extensionName._fromState,
$navigatorKey
$routesBit
Expand Down
2 changes: 1 addition & 1 deletion packages/go_router_builder/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: go_router_builder
description: >-
A builder that supports generated strongly-typed route helpers for
package:go_router
version: 2.0.0
version: 2.0.1
repository: https://github.com/flutter/packages/tree/main/packages/go_router_builder
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router_builder%22

Expand Down
2 changes: 2 additions & 0 deletions packages/go_router_builder/test/builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ const Set<String> _expectedAnnotatedTests = <String>{
'NullableDefaultValueRoute',
'IterableWithEnumRoute',
'IterableDefaultValueRoute',
'NamedRoute',
'NamedEscapedRoute',
};
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,54 @@ class IterableDefaultValueRoute extends GoRouteData {
IterableDefaultValueRoute({this.param = const <int>[0]});
final Iterable<int> param;
}

@ShouldGenerate(r'''
RouteBase get $namedRoute => GoRouteData.$route(
path: '/named-route',
name: 'namedRoute',
dancamdev marked this conversation as resolved.
Show resolved Hide resolved
factory: $NamedRouteExtension._fromState,
);
extension $NamedRouteExtension on NamedRoute {
static NamedRoute _fromState(GoRouterState state) => NamedRoute();
String get location => GoRouteData.$location(
'/named-route',
);
void go(BuildContext context) => context.go(location);
Future<T?> push<T>(BuildContext context) => context.push<T>(location);
void pushReplacement(BuildContext context) =>
context.pushReplacement(location);
}
''')
@TypedGoRoute<NamedRoute>(path: '/named-route', name: 'namedRoute')
class NamedRoute extends GoRouteData {}

@ShouldGenerate(r'''
RouteBase get $namedEscapedRoute => GoRouteData.$route(
path: '/named-route',
name: r'named$Route',
factory: $NamedEscapedRouteExtension._fromState,
);
extension $NamedEscapedRouteExtension on NamedEscapedRoute {
static NamedEscapedRoute _fromState(GoRouterState state) =>
NamedEscapedRoute();
String get location => GoRouteData.$location(
'/named-route',
);
void go(BuildContext context) => context.go(location);
Future<T?> push<T>(BuildContext context) => context.push<T>(location);
void pushReplacement(BuildContext context) =>
context.pushReplacement(location);
}
''')
@TypedGoRoute<NamedEscapedRoute>(path: '/named-route', name: r'named$Route')
class NamedEscapedRoute extends GoRouteData {}