Skip to content

Commit ead879a

Browse files
committed
Update based on feedback
1 parent 53a7c6e commit ead879a

9 files changed

+55
-45
lines changed

packages/go_router_builder/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,8 @@ An example is available [here](https://github.com/flutter/packages/blob/main/pac
455455

456456
## Relative routes
457457

458-
Define a relative route by extending RelativeGoRouteData.
458+
Relative routes allow reusing the same `RouteData` in different parts of the route tree.
459+
Define a relative route by extending `RelativeGoRouteData`.
459460

460461
<?code-excerpt "example/lib/readme_excerpts.dart (relativeRoute)"?>
461462
```dart

packages/go_router_builder/example/lib/go_relative.g.dart

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/go_router_builder/example/lib/readme_excerpts.g.dart

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/go_router_builder/lib/src/route_config.dart

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,9 @@ class StatefulShellBranchConfig extends RouteBaseConfig {
190190
mixin _GoRouteMixin on RouteBaseConfig {
191191
String get _basePathForLocation;
192192

193-
late final Set<String> _pathParams =
194-
pathParametersFromPattern(_basePathForLocation);
193+
late final Set<String> _pathParams = pathParametersFromPattern(
194+
_basePathForLocation,
195+
);
195196

196197
// construct path bits using parent bits
197198
// if there are any queryParam objects, add in the `queryParam` bits
@@ -377,7 +378,7 @@ mixin _GoRouteMixin on RouteBaseConfig {
377378
Iterable<String> _enumDeclarations() {
378379
final Set<InterfaceType> enumParamTypes = <InterfaceType>{};
379380

380-
for (final ParameterElement ctorParam in <ParameterElement>[
381+
for (final FormalParameterElement ctorParam in <FormalParameterElement>[
381382
..._ctorParams,
382383
..._ctorQueryParams,
383384
]) {
@@ -461,7 +462,7 @@ class GoRouteConfig extends RouteBaseConfig with _GoRouteMixin {
461462
}
462463

463464
return '''
464-
mixin $_mixinName on GoRouteData {
465+
mixin $_mixinName on $routeDataClassName {
465466
static $_className _fromState(GoRouterState state) $_fromStateConstructor
466467
$_castedSelf
467468
@override
@@ -522,7 +523,8 @@ class RelativeGoRouteConfig extends RouteBaseConfig with _GoRouteMixin {
522523

523524
@override
524525
String get _mixinDefinition {
525-
final bool hasMixin = getNodeDeclaration<ClassDeclaration>(routeDataClass)
526+
final bool hasMixin =
527+
getNodeDeclaration<ClassDeclaration>(routeDataClass)
526528
?.withClause
527529
?.mixinTypes
528530
.any((NamedType e) => e.name2.toString() == _mixinName) ??
@@ -536,14 +538,14 @@ class RelativeGoRouteConfig extends RouteBaseConfig with _GoRouteMixin {
536538
}
537539

538540
return '''
539-
mixin $_mixinName on RelativeGoRouteData {
541+
mixin $_mixinName on $routeDataClassName {
540542
static $_className _fromState(GoRouterState state) $_fromStateConstructor
541543
$_castedSelf
542544
@override
543-
String get location => RelativeGoRouteData.\$location($_locationArgs,$_locationQueryParams);
545+
String get subpath => RelativeGoRouteData.\$location($_locationArgs,$_locationQueryParams);
544546
545547
@override
546-
String get relativeLocation => './\$location';
548+
String get relativeLocation => './\$subpath';
547549
548550
@override
549551
void goRelative(BuildContext context) =>
@@ -749,12 +751,19 @@ abstract class RouteBaseConfig {
749751
throw UnsupportedError('Unrecognized type $typeName');
750752
}
751753

752-
value._children.addAll(reader
753-
.read(_generateChildrenGetterName(typeName))
754-
.listValue
755-
.map<RouteBaseConfig>((DartObject e) => RouteBaseConfig._fromAnnotation(
756-
ConstantReader(e), element, value,
757-
isAncestorRelative: isRelative),),);
754+
value._children.addAll(
755+
reader
756+
.read(_generateChildrenGetterName(typeName))
757+
.listValue
758+
.map<RouteBaseConfig>(
759+
(DartObject e) => RouteBaseConfig._fromAnnotation(
760+
ConstantReader(e),
761+
element,
762+
value,
763+
isAncestorRelative: isRelative,
764+
),
765+
),
766+
);
758767

759768
return value;
760769
}

packages/go_router_builder/test_inputs/go_relative.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ mixin _$InnerRelativeRoute {}
1111

1212
const TypedRelativeGoRoute<RelativeRoute> relativeRoute =
1313
TypedRelativeGoRoute<RelativeRoute>(
14-
path: 'relative-route',
15-
routes: <TypedRoute<RouteData>>[
16-
TypedRelativeGoRoute<InnerRelativeRoute>(path: 'inner-relative-route')
17-
],
18-
);
14+
path: 'relative-route',
15+
routes: <TypedRoute<RouteData>>[
16+
TypedRelativeGoRoute<InnerRelativeRoute>(path: 'inner-relative-route'),
17+
],
18+
);
1919

2020
@TypedGoRoute<Route1>(
2121
path: 'route-1',

packages/go_router_builder/test_inputs/go_relative.dart.expect

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ mixin _$RelativeRoute on RelativeGoRouteData {
4141
static RelativeRoute _fromState(GoRouterState state) => const RelativeRoute();
4242

4343
@override
44-
String get location => RelativeGoRouteData.$location(
44+
String get subpath => RelativeGoRouteData.$location(
4545
'relative-route',
4646
);
4747

4848
@override
49-
String get relativeLocation => './$location';
49+
String get relativeLocation => './$subpath';
5050

5151
@override
5252
void goRelative(BuildContext context) => context.go(relativeLocation);
@@ -69,12 +69,12 @@ mixin _$InnerRelativeRoute on RelativeGoRouteData {
6969
const InnerRelativeRoute();
7070

7171
@override
72-
String get location => RelativeGoRouteData.$location(
72+
String get subpath => RelativeGoRouteData.$location(
7373
'inner-relative-route',
7474
);
7575

7676
@override
77-
String get relativeLocation => './$location';
77+
String get relativeLocation => './$subpath';
7878

7979
@override
8080
void goRelative(BuildContext context) => context.go(relativeLocation);

packages/go_router_builder/test_inputs/relative_route_with_absolute_path.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import 'package:go_router/go_router.dart';
66

77
mixin _$RelativeRoute {}
88

9-
@TypedRelativeGoRoute<RelativeRoute>(
10-
path: '/relative-route',
11-
)
9+
@TypedRelativeGoRoute<RelativeRoute>(path: '/relative-route')
1210
class RelativeRoute extends RelativeGoRouteData with _$RelativeRoute {
1311
const RelativeRoute();
1412
}

packages/go_router_builder/test_inputs/relative_route_with_direct_absolute_sub_route.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class HomeRoute extends GoRouteData with _$HomeRoute {
1818

1919
const TypedRelativeGoRoute<RelativeRoute> relativeRoute =
2020
TypedRelativeGoRoute<RelativeRoute>(
21-
path: 'relative-route',
22-
routes: <TypedRoute<RouteData>>[
23-
TypedGoRoute<NonRelativeRoute>(path: 'non-relative-route'),
24-
],
25-
);
21+
path: 'relative-route',
22+
routes: <TypedRoute<RouteData>>[
23+
TypedGoRoute<NonRelativeRoute>(path: 'non-relative-route'),
24+
],
25+
);
2626

2727
class RelativeRoute extends RelativeGoRouteData with _$RelativeRoute {
2828
const RelativeRoute();

packages/go_router_builder/test_inputs/relative_route_with_indirect_absolute_sub_route.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ class HomeRoute extends GoRouteData with _$HomeRoute {
1919

2020
const TypedRelativeGoRoute<RelativeRoute> relativeRoute =
2121
TypedRelativeGoRoute<RelativeRoute>(
22-
path: 'relative-route',
23-
routes: <TypedRoute<RouteData>>[shellRoute],
24-
);
22+
path: 'relative-route',
23+
routes: <TypedRoute<RouteData>>[shellRoute],
24+
);
2525

26-
const TypedShellRoute<ShellRoute> shellRoute =
27-
TypedShellRoute<ShellRoute>(routes: <TypedRoute<RouteData>>[absoluteRoute]);
26+
const TypedShellRoute<ShellRoute> shellRoute = TypedShellRoute<ShellRoute>(
27+
routes: <TypedRoute<RouteData>>[absoluteRoute],
28+
);
2829

29-
const TypedGoRoute<AbsoluteRoute> absoluteRoute =
30-
TypedGoRoute<AbsoluteRoute>(path: 'absolute-route');
30+
const TypedGoRoute<AbsoluteRoute> absoluteRoute = TypedGoRoute<AbsoluteRoute>(
31+
path: 'absolute-route',
32+
);
3133

3234
class RelativeRoute extends RelativeGoRouteData with _$RelativeRoute {
3335
const RelativeRoute();

0 commit comments

Comments
 (0)