Skip to content

[go_router_builder] Add caseSensitive to TypedGoRoute #9096

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions packages/go_router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 15.1.0

- Adds `caseSensitive` to `TypedGoRoute`.

## 15.0.0

- **BREAKING CHANGE**
Expand Down
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 @@ -369,6 +369,7 @@ class TypedGoRoute<T extends GoRouteData> extends TypedRoute<T> {
required this.path,
this.name,
this.routes = const <TypedRoute<RouteData>>[],
this.caseSensitive = true,
});

/// The path that corresponds to this route.
Expand All @@ -390,6 +391,17 @@ class TypedGoRoute<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
2 changes: 1 addition & 1 deletion packages/go_router/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: go_router
description: A declarative router for Flutter based on Navigation 2 supporting
deep linking, data-driven routes and more
version: 15.0.0
version: 15.1.0
repository: https://github.com/flutter/packages/tree/main/packages/go_router
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22

Expand Down
46 changes: 46 additions & 0 deletions packages/go_router/test/route_data_test.dart
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too convinced by the tests I wrote. Any idea for a better test?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine, the real test will be in the go_router_builder I think

Original file line number Diff line number Diff line change
Expand Up @@ -492,4 +492,50 @@ void main() {
expect(find.byKey(const Key('buildPage')), findsNothing);
},
);
test('TypedGoRoute with default parameters', () {
const TypedGoRoute<GoRouteData> typedGoRoute = TypedGoRoute<GoRouteData>(
path: '/path',
);

expect(typedGoRoute.path, '/path');
expect(typedGoRoute.name, isNull);
expect(typedGoRoute.caseSensitive, true);
expect(typedGoRoute.routes, isEmpty);
});

test('TypedGoRoute with provided parameters', () {
const TypedGoRoute<GoRouteData> typedGoRoute = TypedGoRoute<GoRouteData>(
path: '/path',
name: 'name',
caseSensitive: false,
routes: <TypedRoute<RouteData>>[
TypedGoRoute<GoRouteData>(
path: 'sub-path',
name: 'subName',
caseSensitive: false,
),
],
);

expect(typedGoRoute.path, '/path');
expect(typedGoRoute.name, 'name');
expect(typedGoRoute.caseSensitive, false);
expect(typedGoRoute.routes, hasLength(1));
expect(
typedGoRoute.routes.single,
isA<TypedGoRoute<GoRouteData>>()
.having((TypedGoRoute<GoRouteData> route) => route.path, 'path',
'sub-path')
.having(
(TypedGoRoute<GoRouteData> route) => route.name,
'name',
'subName',
)
.having(
(TypedGoRoute<GoRouteData> route) => route.caseSensitive,
'caseSensitive',
false,
),
);
});
}