Skip to content

[go_router] Replaces uri related properties in GoRouterState #4392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 21, 2023
Merged
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
7 changes: 7 additions & 0 deletions packages/go_router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 10.0.0

- **BREAKING CHANGE**:
- Replaces location, queryParameters, and queryParametersAll in GoRouterState with Uri.
- See [Migrating to 10.0.0](https://flutter.dev/go/go-router-v10-breaking-changes) or
run `dart fix --apply` to fix the breakages.

## 9.1.1

- Fixes a link in error handling documentation.
Expand Down
18 changes: 14 additions & 4 deletions packages/go_router/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ See the API documentation for details on the following topics:
- [Named routes](https://pub.dev/documentation/go_router/latest/topics/Named%20routes-topic.html)
- [Error handling](https://pub.dev/documentation/go_router/latest/topics/Error%20handling-topic.html)

## Migration guides
## Migration Guides
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

link 404 not found

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to wait for this pr flutter/website#9092

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pr merged

- [Migrating to 10.0.0](https://flutter.dev/go/go-router-v10-breaking-changes).
- [Migrating to 9.0.0](https://flutter.dev/go/go-router-v9-breaking-changes).
- [Migrating to 8.0.0](https://flutter.dev/go/go-router-v8-breaking-changes).
- [Migrating to 7.0.0](https://flutter.dev/go/go-router-v7-breaking-changes).
Expand All @@ -53,6 +54,15 @@ See the
[Changelog](https://github.com/flutter/packages/blob/main/packages/go_router/CHANGELOG.md)
for a list of new features and breaking changes.

## Roadmap
See the [GitHub project](https://github.com/orgs/flutter/projects/17/) for a
prioritized list of feature requests and known issues.
## Triage
See the [GitHub issues](https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-asc+label%3Ateam-go_router+)
for all Go Router issues.

The project follows the same priority system as flutter framework.
[P0](https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-asc+label%3Ateam-go_router+label%3AP0+)
[P1](https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-asc+label%3Ateam-go_router+label%3AP1+)
[P2](https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-asc+label%3Ateam-go_router+label%3AP2+)
[P3](https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-asc+label%3Ateam-go_router+label%3AP3+)

[Package PRs](https://github.com/flutter/packages/pulls?q=is%3Apr+is%3Aopen+label%3A%22p%3A+go_router%22%2C%22p%3A+go_router_builder%22)

2 changes: 1 addition & 1 deletion packages/go_router/example/lib/exception_handling.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void main() => runApp(const MyApp());
/// The route configuration.
final GoRouter _router = GoRouter(
onException: (_, GoRouterState state, GoRouter router) {
router.go('/404', extra: state.location);
router.go('/404', extra: state.uri.toString());
},
routes: <RouteBase>[
GoRoute(
Expand Down
2 changes: 1 addition & 1 deletion packages/go_router/example/lib/others/push.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class App extends StatelessWidget {
path: '/page2',
builder: (BuildContext context, GoRouterState state) =>
Page2ScreenWithPush(
int.parse(state.queryParameters['push-count']!),
int.parse(state.uri.queryParameters['push-count']!),
),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class App extends StatelessWidget {
builder: (BuildContext context, GoRouterState state) {
return FamilyScreen(
fid: state.pathParameters['fid']!,
asc: state.queryParameters['sort'] == 'asc',
asc: state.uri.queryParameters['sort'] == 'asc',
);
}),
],
Expand Down
2 changes: 1 addition & 1 deletion packages/go_router/example/lib/shell_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class ScaffoldWithNavBar extends StatelessWidget {
}

static int _calculateSelectedIndex(BuildContext context) {
final String location = GoRouterState.of(context).location;
final String location = GoRouterState.of(context).uri.toString();
if (location.startsWith('/a')) {
return 0;
}
Expand Down
36 changes: 36 additions & 0 deletions packages/go_router/lib/fix_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,42 @@

version: 1
transforms:
- title: "Replaces 'location' in 'GoRouterState' with `uri.toString()`"
date: 2023-07-06
bulkApply: true
element:
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
field: 'location'
inClass: 'GoRouterState'
changes:
- kind: 'rename'
newName: 'uri.toString()'

- title: "Replaces 'queryParameters' in 'GoRouterState' with `uri.queryParameters`"
date: 2023-07-06
bulkApply: true
element:
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
field: 'queryParameters'
inClass: 'GoRouterState'
changes:
- kind: 'rename'
newName: 'uri.queryParameters'

- title: "Replaces 'queryParametersAll' in 'GoRouterState' with `uri.queryParametersAll`"
date: 2023-07-06
bulkApply: true
element:
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
field: 'queryParametersAll'
inClass: 'GoRouterState'
changes:
- kind: 'rename'
newName: 'uri.queryParametersAll'

- title: "Replaces 'params' and 'queryParams' in 'GoRouter.replaceNamed' with `pathParameters` and `queryParameters`"
date: 2023-04-24
bulkApply: true
Expand Down
13 changes: 4 additions & 9 deletions packages/go_router/lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,14 @@ class RouteBuilder {
}
return GoRouterState(
configuration,
location: effectiveMatchList.uri.toString(),
uri: effectiveMatchList.uri,
matchedLocation: match.matchedLocation,
name: name,
path: path,
fullPath: effectiveMatchList.fullPath,
pathParameters:
Map<String, String>.from(effectiveMatchList.pathParameters),
error: effectiveMatchList.error,
queryParameters: effectiveMatchList.uri.queryParameters,
queryParametersAll: effectiveMatchList.uri.queryParametersAll,
extra: effectiveMatchList.extra,
pageKey: match.pageKey,
);
Expand Down Expand Up @@ -467,7 +465,7 @@ class RouteBuilder {
name: state.name ?? state.path,
arguments: <String, String>{
...state.pathParameters,
...state.queryParameters
...state.uri.queryParameters
},
restorationId: state.pageKey.value,
child: child,
Expand All @@ -491,18 +489,15 @@ class RouteBuilder {
);

GoRouterState _buildErrorState(RouteMatchList matchList) {
final String location = matchList.uri.toString();
assert(matchList.isError);
return GoRouterState(
configuration,
location: location,
uri: matchList.uri,
matchedLocation: matchList.uri.path,
fullPath: matchList.fullPath,
pathParameters: matchList.pathParameters,
queryParameters: matchList.uri.queryParameters,
queryParametersAll: matchList.uri.queryParametersAll,
error: matchList.error,
pageKey: ValueKey<String>('$location(error)'),
pageKey: ValueKey<String>('${matchList.uri}(error)'),
);
}

Expand Down
8 changes: 2 additions & 6 deletions packages/go_router/lib/src/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,12 @@ class RouteConfiguration {
GoRouterState buildTopLevelGoRouterState(RouteMatchList matchList) {
return GoRouterState(
this,
location: matchList.uri.toString(),
uri: matchList.uri,
// No name available at the top level trim the query params off the
// sub-location to match route.redirect
fullPath: matchList.fullPath,
pathParameters: matchList.pathParameters,
matchedLocation: matchList.uri.path,
queryParameters: matchList.uri.queryParameters,
queryParametersAll: matchList.uri.queryParametersAll,
extra: matchList.extra,
pageKey: const ValueKey<String>('topLevel'),
);
Expand Down Expand Up @@ -467,15 +465,13 @@ class RouteConfiguration {
context,
GoRouterState(
this,
location: matchList.uri.toString(),
uri: matchList.uri,
matchedLocation: match.matchedLocation,
name: route.name,
path: route.path,
fullPath: matchList.fullPath,
extra: matchList.extra,
pathParameters: matchList.pathParameters,
queryParameters: matchList.uri.queryParameters,
queryParametersAll: matchList.uri.queryParametersAll,
pageKey: match.pageKey,
),
);
Expand Down
40 changes: 14 additions & 26 deletions packages/go_router/lib/src/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,20 @@ class GoRouterState {
/// Default constructor for creating route state during routing.
const GoRouterState(
this._configuration, {
required this.location,
required this.uri,
required this.matchedLocation,
this.name,
this.path,
required this.fullPath,
required this.pathParameters,
required this.queryParameters,
required this.queryParametersAll,
this.extra,
this.error,
required this.pageKey,
});
final RouteConfiguration _configuration;

/// The full location of the route, e.g. /family/f2/person/p1
final String location;
/// The full uri of the route, e.g. /family/f2/person/p1?filter=name#fragment
final Uri uri;

/// The matched location until this point.
///
Expand Down Expand Up @@ -63,13 +61,6 @@ class GoRouterState {
/// The parameters for this match, e.g. {'fid': 'f2'}
final Map<String, String> pathParameters;

/// The query parameters for the location, e.g. {'from': '/family/f2'}
final Map<String, String> queryParameters;

/// The query parameters for the location,
/// e.g. `{'q1': ['v1'], 'q2': ['v2', 'v3']}`
final Map<String, List<String>> queryParametersAll;

/// An extra object to pass along with the navigation.
final Object? extra;

Expand Down Expand Up @@ -150,32 +141,29 @@ class GoRouterState {
@override
bool operator ==(Object other) {
return other is GoRouterState &&
other.location == location &&
other.uri == uri &&
other.matchedLocation == matchedLocation &&
other.name == name &&
other.path == path &&
other.fullPath == fullPath &&
other.pathParameters == pathParameters &&
other.queryParameters == queryParameters &&
other.queryParametersAll == queryParametersAll &&
other.extra == extra &&
other.error == error &&
other.pageKey == pageKey;
}

@override
int get hashCode => Object.hash(
location,
matchedLocation,
name,
path,
fullPath,
pathParameters,
queryParameters,
queryParametersAll,
extra,
error,
pageKey);
uri,
matchedLocation,
name,
path,
fullPath,
pathParameters,
extra,
error,
pageKey,
);
}

/// An inherited widget to host a [GoRouterStateRegistry] for the subtree.
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: 9.1.1
version: 10.0.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
2 changes: 1 addition & 1 deletion packages/go_router/test/exception_handling_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void main() {
Text('redirected ${state.extra}')),
], tester,
onException: (_, GoRouterState state, GoRouter router) =>
router.go('/error', extra: state.location));
router.go('/error', extra: state.uri.toString()));
expect(find.text('redirected /'), findsOneWidget);

router.go('/some-other-location');
Expand Down
20 changes: 11 additions & 9 deletions packages/go_router/test/go_router_state_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ void main() {
path: '/',
builder: (BuildContext context, _) {
final GoRouterState state = GoRouterState.of(context);
return Text('/ ${state.queryParameters['p']}');
return Text('/ ${state.uri.queryParameters['p']}');
}),
GoRoute(
path: '/a',
builder: (BuildContext context, _) {
final GoRouterState state = GoRouterState.of(context);
return Text('/a ${state.queryParameters['p']}');
return Text('/a ${state.uri.queryParameters['p']}');
}),
];
final GoRouter router = await createRouter(routes, tester);
Expand All @@ -42,15 +42,15 @@ void main() {
path: '/',
builder: (_, __) {
return Builder(builder: (BuildContext context) {
return Text('1 ${GoRouterState.of(context).location}');
return Text('1 ${GoRouterState.of(context).uri}');
});
},
routes: <GoRoute>[
GoRoute(
path: 'a',
builder: (_, __) {
return Builder(builder: (BuildContext context) {
return Text('2 ${GoRouterState.of(context).location}');
return Text('2 ${GoRouterState.of(context).uri}');
});
}),
]),
Expand All @@ -74,7 +74,7 @@ void main() {
path: '/',
builder: (_, __) {
return Builder(builder: (BuildContext context) {
return Text('1 ${GoRouterState.of(context).location}');
return Text('1 ${GoRouterState.of(context).uri}');
});
},
routes: <GoRoute>[
Expand Down Expand Up @@ -110,15 +110,16 @@ void main() {
path: '/',
builder: (_, __) {
return Builder(builder: (BuildContext context) {
return Text(GoRouterState.of(context).location);
return Text(GoRouterState.of(context).uri.toString());
});
},
routes: <GoRoute>[
GoRoute(
path: 'a',
builder: (_, __) {
return Builder(builder: (BuildContext context) {
return Text(key: key, GoRouterState.of(context).location);
return Text(
key: key, GoRouterState.of(context).uri.toString());
});
}),
]),
Expand Down Expand Up @@ -152,15 +153,16 @@ void main() {
path: '/',
builder: (_, __) {
return Builder(builder: (BuildContext context) {
return Text(GoRouterState.of(context).location);
return Text(GoRouterState.of(context).uri.toString());
});
},
routes: <GoRoute>[
GoRoute(
path: 'a',
builder: (_, __) {
return Builder(builder: (BuildContext context) {
return Text(key: key, GoRouterState.of(context).location);
return Text(
key: key, GoRouterState.of(context).uri.toString());
});
}),
]),
Expand Down
Loading