Skip to content
Open
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 @@
# 17.1.0

- Adds `TypedGoRouteParameter` annotation to override parameter names in `TypedGoRoute` constructors.

## 17.0.1

- Fixes an issue where `onEnter` blocking causes navigation stack loss (stale state restoration).
Expand Down
26 changes: 26 additions & 0 deletions packages/go_router/lib/src/route_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -619,3 +619,29 @@ class NoOpPage extends Page<void> {
Route<void> createRoute(BuildContext context) =>
throw UnsupportedError('Should never be called');
}

/// Annotation to override the URI name for a route parameter.
@Target({TargetKind.parameter})
class TypedGoRouteParameter {
/// Annotation to override the URI name for a route parameter.
const TypedGoRouteParameter({this.name});

/// The name of the parameter in the URI.
///
/// If `null`, the kebab-case version of the parameter name will be used.
///
/// For example:
/// ```dart
/// class MyRoute extends GoRouteData with $MyRoute {
/// const MyRoute({
/// @TypedGoRouteParameter(name: 'custom_name') this.myParameter,
/// });
/// final String myParameter;
/// }
/// ```
///
/// This will result in a route that matches
/// `/my-route?custom_name=some_value` instead of the default
/// `/my-route?my-parameter=some_value`.
final String? name;
}
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: 17.0.1
version: 17.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
6 changes: 6 additions & 0 deletions packages/go_router/test/route_data_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -794,4 +794,10 @@ void main() {
),
);
});

test('TypedGoRouteParameter stores the name', () {
const parameter = TypedGoRouteParameter(name: 'customName');

expect(parameter.name, 'customName');
});
}
Loading