Skip to content

Commit

Permalink
[go_router] Adds name to TypedGoRoute (flutter#3702)
Browse files Browse the repository at this point in the history
This PR is required for [flutter#3665](flutter#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)
  • Loading branch information
dancamdev authored and nploi committed Jul 16, 2023
1 parent 7077bb4 commit b47ddbb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
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 @@
## 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.
Expand Down
11 changes: 11 additions & 0 deletions packages/go_router/lib/src/route_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ abstract class GoRouteData extends RouteData {
/// 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>[],
Expand Down Expand Up @@ -106,6 +107,7 @@ abstract class GoRouteData extends RouteData {

return GoRoute(
path: path,
name: name,
builder: builder,
pageBuilder: pageBuilder,
redirect: redirect,
Expand Down Expand Up @@ -223,6 +225,7 @@ class TypedGoRoute<T extends GoRouteData> extends TypedRoute<T> {
/// Default const constructor
const TypedGoRoute({
required this.path,
this.name,
this.routes = const <TypedRoute<RouteData>>[],
});

Expand All @@ -233,6 +236,14 @@ class TypedGoRoute<T extends GoRouteData> extends TypedRoute<T> {
///
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].
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: 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

Expand Down

0 comments on commit b47ddbb

Please sign in to comment.