Skip to content

Commit 195d875

Browse files
committed
Update based on feedback
1 parent e372b0e commit 195d875

9 files changed

+54
-44
lines changed

packages/go_router_builder/README.md

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

458458
## Relative routes
459459

460-
Define a relative route by extending RelativeGoRouteData.
460+
Relative routes allow reusing the same `RouteData` in different parts of the route tree.
461+
Define a relative route by extending `RelativeGoRouteData`.
461462

462463
<?code-excerpt "example/lib/readme_excerpts.dart (relativeRoute)"?>
463464
```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: 22 additions & 13 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
@@ -467,7 +468,7 @@ class GoRouteConfig extends RouteBaseConfig with _GoRouteMixin {
467468
}
468469

469470
return '''
470-
mixin $_mixinName on GoRouteData {
471+
mixin $_mixinName on $routeDataClassName {
471472
static $_className _fromState(GoRouterState state) $_fromStateConstructor
472473
$_castedSelf
473474
@override
@@ -527,7 +528,8 @@ class RelativeGoRouteConfig extends RouteBaseConfig with _GoRouteMixin {
527528

528529
@override
529530
String get _mixinDefinition {
530-
final bool hasMixin = getNodeDeclaration<ClassDeclaration>(routeDataClass)
531+
final bool hasMixin =
532+
getNodeDeclaration<ClassDeclaration>(routeDataClass)
531533
?.withClause
532534
?.mixinTypes
533535
.any((NamedType e) => e.name2.toString() == _mixinName) ??
@@ -541,14 +543,14 @@ class RelativeGoRouteConfig extends RouteBaseConfig with _GoRouteMixin {
541543
}
542544

543545
return '''
544-
mixin $_mixinName on RelativeGoRouteData {
546+
mixin $_mixinName on $routeDataClassName {
545547
static $_className _fromState(GoRouterState state) $_fromStateConstructor
546548
$_castedSelf
547549
@override
548-
String get location => RelativeGoRouteData.\$location($_locationArgs,$_locationQueryParams);
550+
String get subpath => RelativeGoRouteData.\$location($_locationArgs,$_locationQueryParams);
549551
550552
@override
551-
String get relativeLocation => './\$location';
553+
String get relativeLocation => './\$subpath';
552554
553555
@override
554556
void goRelative(BuildContext context) =>
@@ -754,12 +756,19 @@ abstract class RouteBaseConfig {
754756
throw UnsupportedError('Unrecognized type $typeName');
755757
}
756758

757-
value._children.addAll(reader
758-
.read(_generateChildrenGetterName(typeName))
759-
.listValue
760-
.map<RouteBaseConfig>((DartObject e) => RouteBaseConfig._fromAnnotation(
761-
ConstantReader(e), element, value,
762-
isAncestorRelative: isRelative),),);
759+
value._children.addAll(
760+
reader
761+
.read(_generateChildrenGetterName(typeName))
762+
.listValue
763+
.map<RouteBaseConfig>(
764+
(DartObject e) => RouteBaseConfig._fromAnnotation(
765+
ConstantReader(e),
766+
element,
767+
value,
768+
isAncestorRelative: isRelative,
769+
),
770+
),
771+
);
763772

764773
return value;
765774
}

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)