[go_router] Adds name to TypedGoRoute (#3702)
This PR is required for [#3665](https://github.com/flutter/packages/pull/3665) to work and be merged.
It should allow for generating `TypedGoRoutes` by defining a custom name and forwarding it to the underlying GoRoute. This is needed when working with Analytics services such as Google analytics that use the `RouteSettings.name` to log the page in their systems.
*List which issues are fixed by this PR. You must list at least one issue.*
[#120102](https://github.com/flutter/flutter/issues/120102)
diff --git a/packages/go_router/CHANGELOG.md b/packages/go_router/CHANGELOG.md
index 00c6388..0977df2 100644
--- a/packages/go_router/CHANGELOG.md
+++ b/packages/go_router/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 6.5.8
+
+- Adds name parameter to `TypedGoRoute`
+
## 6.5.7
- Fixes a bug that go_router would crash if `GoRoute.pageBuilder` depends on `InheritedWidget`s.
diff --git a/packages/go_router/lib/src/route_data.dart b/packages/go_router/lib/src/route_data.dart
index 3530ca2..fbf3961 100644
--- a/packages/go_router/lib/src/route_data.dart
+++ b/packages/go_router/lib/src/route_data.dart
@@ -79,6 +79,7 @@
/// Should not be used directly.
static GoRoute $route<T extends GoRouteData>({
required String path,
+ String? name,
required T Function(GoRouterState) factory,
GlobalKey<NavigatorState>? parentNavigatorKey,
List<RouteBase> routes = const <RouteBase>[],
@@ -106,6 +107,7 @@
return GoRoute(
path: path,
+ name: name,
builder: builder,
pageBuilder: pageBuilder,
redirect: redirect,
@@ -223,6 +225,7 @@
/// Default const constructor
const TypedGoRoute({
required this.path,
+ this.name,
this.routes = const <TypedRoute<RouteData>>[],
});
@@ -233,6 +236,14 @@
///
final String path;
+ /// The name that corresponds to this route.
+ /// Used by Analytics services such as Firebase Analytics
+ /// to log the screen views in their system.
+ ///
+ /// See [GoRoute.name].
+ ///
+ final String? name;
+
/// Child route definitions.
///
/// See [RouteBase.routes].
diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml
index 1bd6279..3d1562d 100644
--- a/packages/go_router/pubspec.yaml
+++ b/packages/go_router/pubspec.yaml
@@ -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: 6.5.7
+version: 6.5.8
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