Skip to content

Commit 412030e

Browse files
[go_router_builder] Add caseSensitive to TypedGoRoute (#9096)
First part of flutter/flutter#167277 ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent ac21f53 commit 412030e

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

packages/go_router/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 15.1.0
2+
3+
- Adds `caseSensitive` to `TypedGoRoute`.
4+
15
## 15.0.0
26

37
- **BREAKING CHANGE**

packages/go_router/lib/src/route_data.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ class TypedGoRoute<T extends GoRouteData> extends TypedRoute<T> {
369369
required this.path,
370370
this.name,
371371
this.routes = const <TypedRoute<RouteData>>[],
372+
this.caseSensitive = true,
372373
});
373374

374375
/// The path that corresponds to this route.
@@ -390,6 +391,17 @@ class TypedGoRoute<T extends GoRouteData> extends TypedRoute<T> {
390391
///
391392
/// See [RouteBase.routes].
392393
final List<TypedRoute<RouteData>> routes;
394+
395+
/// Determines whether the route matching is case sensitive.
396+
///
397+
/// When `true`, the path must match the specified case. For example,
398+
/// a route with `path: '/family/:fid'` will not match `/FaMiLy/f2`.
399+
///
400+
/// When `false`, the path matching is case insensitive. The route
401+
/// with `path: '/family/:fid'` will match `/FaMiLy/f2`.
402+
///
403+
/// Defaults to `true`.
404+
final bool caseSensitive;
393405
}
394406

395407
/// A superclass for each typed shell route descendant

packages/go_router/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: go_router
22
description: A declarative router for Flutter based on Navigation 2 supporting
33
deep linking, data-driven routes and more
4-
version: 15.0.0
4+
version: 15.1.0
55
repository: https://github.com/flutter/packages/tree/main/packages/go_router
66
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22
77

packages/go_router/test/route_data_test.dart

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,4 +492,50 @@ void main() {
492492
expect(find.byKey(const Key('buildPage')), findsNothing);
493493
},
494494
);
495+
test('TypedGoRoute with default parameters', () {
496+
const TypedGoRoute<GoRouteData> typedGoRoute = TypedGoRoute<GoRouteData>(
497+
path: '/path',
498+
);
499+
500+
expect(typedGoRoute.path, '/path');
501+
expect(typedGoRoute.name, isNull);
502+
expect(typedGoRoute.caseSensitive, true);
503+
expect(typedGoRoute.routes, isEmpty);
504+
});
505+
506+
test('TypedGoRoute with provided parameters', () {
507+
const TypedGoRoute<GoRouteData> typedGoRoute = TypedGoRoute<GoRouteData>(
508+
path: '/path',
509+
name: 'name',
510+
caseSensitive: false,
511+
routes: <TypedRoute<RouteData>>[
512+
TypedGoRoute<GoRouteData>(
513+
path: 'sub-path',
514+
name: 'subName',
515+
caseSensitive: false,
516+
),
517+
],
518+
);
519+
520+
expect(typedGoRoute.path, '/path');
521+
expect(typedGoRoute.name, 'name');
522+
expect(typedGoRoute.caseSensitive, false);
523+
expect(typedGoRoute.routes, hasLength(1));
524+
expect(
525+
typedGoRoute.routes.single,
526+
isA<TypedGoRoute<GoRouteData>>()
527+
.having((TypedGoRoute<GoRouteData> route) => route.path, 'path',
528+
'sub-path')
529+
.having(
530+
(TypedGoRoute<GoRouteData> route) => route.name,
531+
'name',
532+
'subName',
533+
)
534+
.having(
535+
(TypedGoRoute<GoRouteData> route) => route.caseSensitive,
536+
'caseSensitive',
537+
false,
538+
),
539+
);
540+
});
495541
}

0 commit comments

Comments
 (0)