Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
37be48c
- Adds `GoRouter.goRelative`
ThangVuNguyenViet May 29, 2024
f8061ce
add go_relative example for go_router
ThangVuNguyenViet May 29, 2024
8a77147
add go_relative_test for the example
ThangVuNguyenViet May 29, 2024
61127f3
fix failed test
ThangVuNguyenViet May 29, 2024
687b332
replace goRelative with go('./$path')
ThangVuNguyenViet Jun 19, 2024
cca1454
Commit missing files during merge
ThangVuNguyenViet Jun 19, 2024
975128b
update changelog & version
ThangVuNguyenViet Jun 19, 2024
6d90488
Prevent concatenateUris from adding trailing redundant '?'. Add test …
ThangVuNguyenViet Jun 19, 2024
ccb38f9
Add more `concatenateUris` test. Fix joining params
ThangVuNguyenViet Jun 19, 2024
80d85d6
update example description
ThangVuNguyenViet Jul 10, 2024
a09aa94
Make concatenateUris not merging parameters, only take them from chil…
ThangVuNguyenViet Jul 19, 2024
a174cbe
Add GoRelativeRouteConfig
ThangVuNguyenViet Jul 10, 2024
4cb0334
Add test, examples and example tests for go_router_builder. Temporari…
ThangVuNguyenViet Jul 19, 2024
ceaa318
Add relativeLocation, push, pushReplacement & replace to the Relative…
ThangVuNguyenViet Jul 19, 2024
d3b5355
Merge branch 'flutter-main'
ThangVuNguyenViet Jan 22, 2025
07b4a23
update go_router package dependency
ThangVuNguyenViet Jan 22, 2025
6008b8b
Fix merge issues
ThangVuNguyenViet Jan 22, 2025
d2fbc0e
temporarily add dependency_override
ThangVuNguyenViet Jan 22, 2025
8b5fb4d
change relative route actions to have suffix `Relative`
ThangVuNguyenViet Feb 3, 2025
02c3d7b
Fix example
ThangVuNguyenViet Feb 4, 2025
72c06de
Update go_relative test
ThangVuNguyenViet Feb 6, 2025
edef7a5
Merge branch 'main' of github.com:flutter/packages
ThangVuNguyenViet May 17, 2025
5474303
fix generated file
ThangVuNguyenViet May 17, 2025
dbf7f9d
Fix failed test due to generated files
ThangVuNguyenViet May 17, 2025
37c5490
Merge branch 'main' of github.com:flutter/packages
ThangVuNguyenViet Jun 2, 2025
868a2d5
Merge branch 'main' of github.com:flutter/packages
ThangVuNguyenViet Jun 12, 2025
232dc7d
Merge branch 'main' of github.com:flutter/packages
ThangVuNguyenViet Jul 1, 2025
1d5ad11
Merge branch 'main' of github.com:flutter/packages
ThangVuNguyenViet Jul 9, 2025
f899939
Remove GoRouteData routing methods. Update TypedRelativeGoRoute gener…
ThangVuNguyenViet Jul 9, 2025
92f6cac
remove overrides on other tests
ThangVuNguyenViet Jul 9, 2025
f98505e
make sure relative go route generated code resembles typed go route a…
ThangVuNguyenViet Jul 9, 2025
20fd5d6
update changelog
ThangVuNguyenViet Jul 10, 2025
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
Prev Previous commit
Next Next commit
make sure relative go route generated code resembles typed go route a…
…s much as possible. Add case sensitive support. Fix failing tests
  • Loading branch information
ThangVuNguyenViet committed Jul 9, 2025
commit f98505e47302734a87e3328fc55dc4fbee1965f4
12 changes: 12 additions & 0 deletions packages/go_router/lib/src/route_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ class TypedRelativeGoRoute<T extends GoRouteData> extends TypedRoute<T> {
const TypedRelativeGoRoute({
required this.path,
this.routes = const <TypedRoute<RouteData>>[],
this.caseSensitive = true,
});

/// The relative path that corresponds to this route.
Expand All @@ -426,6 +427,17 @@ class TypedRelativeGoRoute<T extends GoRouteData> extends TypedRoute<T> {
///
/// See [RouteBase.routes].
final List<TypedRoute<RouteData>> routes;

/// Determines whether the route matching is case sensitive.
///
/// When `true`, the path must match the specified case. For example,
/// a route with `path: '/family/:fid'` will not match `/FaMiLy/f2`.
///
/// When `false`, the path matching is case insensitive. The route
/// with `path: '/family/:fid'` will match `/FaMiLy/f2`.
///
/// Defaults to `true`.
final bool caseSensitive;
}

/// A superclass for each typed shell route descendant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const String _routeDataUrl = 'package:go_router/src/route_data.dart';

const Map<String, String> _annotations = <String, String>{
'TypedGoRoute': 'GoRouteData',
'TypedRelativeRoute': 'GoRouteData',
'TypedRelativeGoRoute': 'GoRouteData',
'TypedShellRoute': 'ShellRouteData',
'TypedStatefulShellBranch': 'StatefulShellBranchData',
'TypedStatefulShellRoute': 'StatefulShellRouteData',
Expand Down
50 changes: 35 additions & 15 deletions packages/go_router_builder/lib/src/route_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ mixin $_mixinName on GoRouteData {
class GoRelativeRouteConfig extends RouteBaseConfig {
GoRelativeRouteConfig._({
required this.path,
required this.caseSensitive,
required this.parentNavigatorKey,
required super.routeDataClass,
required super.parent,
Expand All @@ -488,6 +489,9 @@ class GoRelativeRouteConfig extends RouteBaseConfig {
/// The path of the GoRoute to be created by this configuration.
final String path;

/// The case sensitivity of the GoRelativeRoute to be created by this configuration.
final bool caseSensitive;

/// The parent navigator key.
final String? parentNavigatorKey;

Expand All @@ -501,9 +505,21 @@ class GoRelativeRouteConfig extends RouteBaseConfig {
// Enum types are encoded using a map, so we need a nullability check
// here to ensure it matches Uri.encodeComponent nullability
final DartType? type = _field(pathParameter)?.returnType;
final String value =
'\${Uri.encodeComponent(${_encodeFor(pathParameter)}${type?.isEnum ?? false ? '!' : ''})}';
return MapEntry<String, String>(pathParameter, value);

final StringBuffer valueBuffer = StringBuffer();

valueBuffer.write(r'${Uri.encodeComponent(');
valueBuffer.write(_encodeFor(pathParameter));

if (type?.isEnum ?? false) {
valueBuffer.write('!');
} else if (type?.isNullableType ?? false) {
valueBuffer.write("?? ''");
}

valueBuffer.write(')}');

return MapEntry<String, String>(pathParameter, valueBuffer.toString());
}),
);
final String location = patternToPath(path, pathParameters);
Expand Down Expand Up @@ -535,6 +551,16 @@ class GoRelativeRouteConfig extends RouteBaseConfig {
return buffer.toString();
}

String get _castedSelf {
if (_pathParams.isEmpty &&
_ctorQueryParams.isEmpty &&
_extraParam == null) {
return '';
}

return '\n$_className get $selfFieldName => this as $_className;\n';
}

String _decodeFor(ParameterElement element) {
if (element.isRequired) {
if (element.type.nullabilitySuffix == NullabilitySuffix.question &&
Expand Down Expand Up @@ -573,16 +599,6 @@ class GoRelativeRouteConfig extends RouteBaseConfig {
return encodeField(field);
}

String get _castedSelf {
if (_pathParams.isEmpty &&
_ctorQueryParams.isEmpty &&
_extraParam == null) {
return '';
}

return '\n$_className get $selfFieldName => this as $_className;\n';
}

String get _locationQueryParams {
if (_ctorQueryParams.isEmpty) {
return '';
Expand All @@ -598,9 +614,11 @@ class GoRelativeRouteConfig extends RouteBaseConfig {
if (param.type.isNullableType) {
throw NullableDefaultValueError(param);
}
conditions.add('$parameterName != ${param.defaultValueCode!}');
conditions.add(
compareField(param, parameterName, param.defaultValueCode!),
);
} else if (param.type.isNullableType) {
conditions.add('$parameterName != null');
conditions.add('$selfFieldName.$parameterName != null');
}
String line = '';
if (conditions.isNotEmpty) {
Expand Down Expand Up @@ -863,8 +881,10 @@ abstract class RouteBaseConfig {
element: element,
);
}
final ConstantReader caseSensitiveValue = reader.read('caseSensitive');
value = GoRelativeRouteConfig._(
path: pathValue.stringValue,
caseSensitive: caseSensitiveValue.boolValue,
routeDataClass: classElement,
parent: parent,
parentNavigatorKey: _generateParameterGetterCode(
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: 3.0.1
version: 3.0.2
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
13 changes: 0 additions & 13 deletions packages/go_router_builder/test_inputs/go_relative.dart.expect
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'go_relative.dart';

// **************************************************************************
// GoRouterGenerator
// **************************************************************************

List<RouteBase> get $appRoutes => [
$route1,
$route2,
];

RouteBase get $route1 => GoRouteData.$route(
path: 'route-1',
factory: _$Route1._fromState,
Expand Down