Skip to content

Commit 5dad90c

Browse files
authored
[go_router] Adds name to TypedGoRoute (#3702)
This PR is required for [#3665](#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](flutter/flutter#120102)
1 parent 2c0fc55 commit 5dad90c

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-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+
## 6.5.8
2+
3+
- Adds name parameter to `TypedGoRoute`
4+
15
## 6.5.7
26

37
- Fixes a bug that go_router would crash if `GoRoute.pageBuilder` depends on `InheritedWidget`s.

packages/go_router/lib/src/route_data.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ abstract class GoRouteData extends RouteData {
7979
/// Should not be used directly.
8080
static GoRoute $route<T extends GoRouteData>({
8181
required String path,
82+
String? name,
8283
required T Function(GoRouterState) factory,
8384
GlobalKey<NavigatorState>? parentNavigatorKey,
8485
List<RouteBase> routes = const <RouteBase>[],
@@ -106,6 +107,7 @@ abstract class GoRouteData extends RouteData {
106107

107108
return GoRoute(
108109
path: path,
110+
name: name,
109111
builder: builder,
110112
pageBuilder: pageBuilder,
111113
redirect: redirect,
@@ -223,6 +225,7 @@ class TypedGoRoute<T extends GoRouteData> extends TypedRoute<T> {
223225
/// Default const constructor
224226
const TypedGoRoute({
225227
required this.path,
228+
this.name,
226229
this.routes = const <TypedRoute<RouteData>>[],
227230
});
228231

@@ -233,6 +236,14 @@ class TypedGoRoute<T extends GoRouteData> extends TypedRoute<T> {
233236
///
234237
final String path;
235238

239+
/// The name that corresponds to this route.
240+
/// Used by Analytics services such as Firebase Analytics
241+
/// to log the screen views in their system.
242+
///
243+
/// See [GoRoute.name].
244+
///
245+
final String? name;
246+
236247
/// Child route definitions.
237248
///
238249
/// See [RouteBase.routes].

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: 6.5.7
4+
version: 6.5.8
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

0 commit comments

Comments
 (0)