Skip to content

Commit 3be5411

Browse files
committed
Replaces uri related properties in GoRouterState
1 parent caabb6f commit 3be5411

17 files changed

+137
-98
lines changed

packages/go_router/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 10.0.0
2+
3+
- **BREAKING CHANGE**:
4+
- Replaces location, queryParameters, and queryParametersAll in GoRouterState with Uri.
5+
- See [Migrating to 10.0.0](https://flutter.dev/go/go-router-v10-breaking-changes) or
6+
run `dart fix --apply` to fix the breakages.
7+
18
## 9.1.1
29

310
- Fixes a link in error handling documentation.

packages/go_router/README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ See the API documentation for details on the following topics:
3636
- [Named routes](https://pub.dev/documentation/go_router/latest/topics/Named%20routes-topic.html)
3737
- [Error handling](https://pub.dev/documentation/go_router/latest/topics/Error%20handling-topic.html)
3838

39-
## Migration guides
39+
## Migration Guides
40+
- [Migrating to 10.0.0](https://flutter.dev/go/go-router-v10-breaking-changes).
4041
- [Migrating to 9.0.0](https://flutter.dev/go/go-router-v9-breaking-changes).
4142
- [Migrating to 8.0.0](https://flutter.dev/go/go-router-v8-breaking-changes).
4243
- [Migrating to 7.0.0](https://flutter.dev/go/go-router-v7-breaking-changes).
@@ -53,6 +54,15 @@ See the
5354
[Changelog](https://github.com/flutter/packages/blob/main/packages/go_router/CHANGELOG.md)
5455
for a list of new features and breaking changes.
5556

56-
## Roadmap
57-
See the [GitHub project](https://github.com/orgs/flutter/projects/17/) for a
58-
prioritized list of feature requests and known issues.
57+
## Triage
58+
See the [GitHub issues](https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-asc+label%3Ateam-go_router+)
59+
for all Go Router issues.
60+
61+
The project follows the same priority system as flutter framework.
62+
[P0](https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-asc+label%3Ateam-go_router+label%3AP0+)
63+
[P1](https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-asc+label%3Ateam-go_router+label%3AP1+)
64+
[P2](https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-asc+label%3Ateam-go_router+label%3AP2+)
65+
[P3](https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-asc+label%3Ateam-go_router+label%3AP3+)
66+
67+
[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)
68+

packages/go_router/example/lib/exception_handling.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void main() => runApp(const MyApp());
1717
/// The route configuration.
1818
final GoRouter _router = GoRouter(
1919
onException: (_, GoRouterState state, GoRouter router) {
20-
router.go('/404', extra: state.location);
20+
router.go('/404', extra: state.uri.toString());
2121
},
2222
routes: <RouteBase>[
2323
GoRoute(

packages/go_router/example/lib/others/push.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class App extends StatelessWidget {
3232
path: '/page2',
3333
builder: (BuildContext context, GoRouterState state) =>
3434
Page2ScreenWithPush(
35-
int.parse(state.queryParameters['push-count']!),
35+
int.parse(state.uri.queryParameters['push-count']!),
3636
),
3737
),
3838
],

packages/go_router/example/lib/path_and_query_parameters.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class App extends StatelessWidget {
8585
builder: (BuildContext context, GoRouterState state) {
8686
return FamilyScreen(
8787
fid: state.pathParameters['fid']!,
88-
asc: state.queryParameters['sort'] == 'asc',
88+
asc: state.uri.queryParameters['sort'] == 'asc',
8989
);
9090
}),
9191
],

packages/go_router/example/lib/shell_route.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class ScaffoldWithNavBar extends StatelessWidget {
152152
}
153153

154154
static int _calculateSelectedIndex(BuildContext context) {
155-
final String location = GoRouterState.of(context).location;
155+
final String location = GoRouterState.of(context).uri.toString();
156156
if (location.startsWith('/a')) {
157157
return 0;
158158
}

packages/go_router/lib/fix_data.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,42 @@
1717

1818
version: 1
1919
transforms:
20+
- title: "Replaces 'location' in 'GoRouterState' with `uri.toString()`"
21+
date: 2023-07-06
22+
bulkApply: true
23+
element:
24+
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
25+
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
26+
field: 'location'
27+
inClass: 'GoRouterState'
28+
changes:
29+
- kind: 'rename'
30+
newName: 'uri.toString()'
31+
32+
- title: "Replaces 'queryParameters' in 'GoRouterState' with `uri.queryParameters`"
33+
date: 2023-07-06
34+
bulkApply: true
35+
element:
36+
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
37+
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
38+
field: 'queryParameters'
39+
inClass: 'GoRouterState'
40+
changes:
41+
- kind: 'rename'
42+
newName: 'uri.queryParameters'
43+
44+
- title: "Replaces 'queryParametersAll' in 'GoRouterState' with `uri.queryParametersAll`"
45+
date: 2023-07-06
46+
bulkApply: true
47+
element:
48+
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
49+
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
50+
field: 'queryParametersAll'
51+
inClass: 'GoRouterState'
52+
changes:
53+
- kind: 'rename'
54+
newName: 'uri.queryParametersAll'
55+
2056
- title: "Replaces 'params' and 'queryParams' in 'GoRouter.replaceNamed' with `pathParameters` and `queryParameters`"
2157
date: 2023-04-24
2258
bulkApply: true

packages/go_router/lib/src/builder.dart

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,16 +339,14 @@ class RouteBuilder {
339339
}
340340
return GoRouterState(
341341
configuration,
342-
location: effectiveMatchList.uri.toString(),
342+
uri: effectiveMatchList.uri,
343343
matchedLocation: match.matchedLocation,
344344
name: name,
345345
path: path,
346346
fullPath: effectiveMatchList.fullPath,
347347
pathParameters:
348348
Map<String, String>.from(effectiveMatchList.pathParameters),
349349
error: effectiveMatchList.error,
350-
queryParameters: effectiveMatchList.uri.queryParameters,
351-
queryParametersAll: effectiveMatchList.uri.queryParametersAll,
352350
extra: effectiveMatchList.extra,
353351
pageKey: match.pageKey,
354352
);
@@ -467,7 +465,7 @@ class RouteBuilder {
467465
name: state.name ?? state.path,
468466
arguments: <String, String>{
469467
...state.pathParameters,
470-
...state.queryParameters
468+
...state.uri.queryParameters
471469
},
472470
restorationId: state.pageKey.value,
473471
child: child,
@@ -491,18 +489,15 @@ class RouteBuilder {
491489
);
492490

493491
GoRouterState _buildErrorState(RouteMatchList matchList) {
494-
final String location = matchList.uri.toString();
495492
assert(matchList.isError);
496493
return GoRouterState(
497494
configuration,
498-
location: location,
495+
uri: matchList.uri,
499496
matchedLocation: matchList.uri.path,
500497
fullPath: matchList.fullPath,
501498
pathParameters: matchList.pathParameters,
502-
queryParameters: matchList.uri.queryParameters,
503-
queryParametersAll: matchList.uri.queryParametersAll,
504499
error: matchList.error,
505-
pageKey: ValueKey<String>('$location(error)'),
500+
pageKey: ValueKey<String>('${matchList.uri}(error)'),
506501
);
507502
}
508503

packages/go_router/lib/src/configuration.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,12 @@ class RouteConfiguration {
202202
GoRouterState buildTopLevelGoRouterState(RouteMatchList matchList) {
203203
return GoRouterState(
204204
this,
205-
location: matchList.uri.toString(),
205+
uri: matchList.uri,
206206
// No name available at the top level trim the query params off the
207207
// sub-location to match route.redirect
208208
fullPath: matchList.fullPath,
209209
pathParameters: matchList.pathParameters,
210210
matchedLocation: matchList.uri.path,
211-
queryParameters: matchList.uri.queryParameters,
212-
queryParametersAll: matchList.uri.queryParametersAll,
213211
extra: matchList.extra,
214212
pageKey: const ValueKey<String>('topLevel'),
215213
);
@@ -467,15 +465,13 @@ class RouteConfiguration {
467465
context,
468466
GoRouterState(
469467
this,
470-
location: matchList.uri.toString(),
468+
uri: matchList.uri,
471469
matchedLocation: match.matchedLocation,
472470
name: route.name,
473471
path: route.path,
474472
fullPath: matchList.fullPath,
475473
extra: matchList.extra,
476474
pathParameters: matchList.pathParameters,
477-
queryParameters: matchList.uri.queryParameters,
478-
queryParametersAll: matchList.uri.queryParametersAll,
479475
pageKey: match.pageKey,
480476
),
481477
);

packages/go_router/lib/src/state.dart

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,20 @@ class GoRouterState {
1616
/// Default constructor for creating route state during routing.
1717
const GoRouterState(
1818
this._configuration, {
19-
required this.location,
19+
required this.uri,
2020
required this.matchedLocation,
2121
this.name,
2222
this.path,
2323
required this.fullPath,
2424
required this.pathParameters,
25-
required this.queryParameters,
26-
required this.queryParametersAll,
2725
this.extra,
2826
this.error,
2927
required this.pageKey,
3028
});
3129
final RouteConfiguration _configuration;
3230

33-
/// The full location of the route, e.g. /family/f2/person/p1
34-
final String location;
31+
/// The full uri of the route, e.g. /family/f2/person/p1?filter=name#fragment
32+
final Uri uri;
3533

3634
/// The matched location until this point.
3735
///
@@ -63,12 +61,12 @@ class GoRouterState {
6361
/// The parameters for this match, e.g. {'fid': 'f2'}
6462
final Map<String, String> pathParameters;
6563

66-
/// The query parameters for the location, e.g. {'from': '/family/f2'}
67-
final Map<String, String> queryParameters;
68-
69-
/// The query parameters for the location,
70-
/// e.g. `{'q1': ['v1'], 'q2': ['v2', 'v3']}`
71-
final Map<String, List<String>> queryParametersAll;
64+
// /// The query parameters for the location, e.g. {'from': '/family/f2'}
65+
// Map<String, String> get queryParameters => uri.queryParameters;
66+
//
67+
// /// The query parameters for the location,
68+
// /// e.g. `{'q1': ['v1'], 'q2': ['v2', 'v3']}`
69+
// Map<String, List<String>> get queryParametersAll => uri.queryParametersAll;
7270

7371
/// An extra object to pass along with the navigation.
7472
final Object? extra;
@@ -150,32 +148,20 @@ class GoRouterState {
150148
@override
151149
bool operator ==(Object other) {
152150
return other is GoRouterState &&
153-
other.location == location &&
151+
other.uri == uri &&
154152
other.matchedLocation == matchedLocation &&
155153
other.name == name &&
156154
other.path == path &&
157155
other.fullPath == fullPath &&
158156
other.pathParameters == pathParameters &&
159-
other.queryParameters == queryParameters &&
160-
other.queryParametersAll == queryParametersAll &&
161157
other.extra == extra &&
162158
other.error == error &&
163159
other.pageKey == pageKey;
164160
}
165161

166162
@override
167-
int get hashCode => Object.hash(
168-
location,
169-
matchedLocation,
170-
name,
171-
path,
172-
fullPath,
173-
pathParameters,
174-
queryParameters,
175-
queryParametersAll,
176-
extra,
177-
error,
178-
pageKey);
163+
int get hashCode => Object.hash(uri, matchedLocation, name, path, fullPath,
164+
pathParameters, extra, error, pageKey);
179165
}
180166

181167
/// An inherited widget to host a [GoRouterStateRegistry] for the subtree.

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: 9.1.1
4+
version: 10.0.0
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

packages/go_router/test/exception_handling_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void main() {
6969
Text('redirected ${state.extra}')),
7070
], tester,
7171
onException: (_, GoRouterState state, GoRouter router) =>
72-
router.go('/error', extra: state.location));
72+
router.go('/error', extra: state.uri.toString()));
7373
expect(find.text('redirected /'), findsOneWidget);
7474

7575
router.go('/some-other-location');

packages/go_router/test/go_router_state_test.dart

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ void main() {
1717
path: '/',
1818
builder: (BuildContext context, _) {
1919
final GoRouterState state = GoRouterState.of(context);
20-
return Text('/ ${state.queryParameters['p']}');
20+
return Text('/ ${state.uri.queryParameters['p']}');
2121
}),
2222
GoRoute(
2323
path: '/a',
2424
builder: (BuildContext context, _) {
2525
final GoRouterState state = GoRouterState.of(context);
26-
return Text('/a ${state.queryParameters['p']}');
26+
return Text('/a ${state.uri.queryParameters['p']}');
2727
}),
2828
];
2929
final GoRouter router = await createRouter(routes, tester);
@@ -42,15 +42,15 @@ void main() {
4242
path: '/',
4343
builder: (_, __) {
4444
return Builder(builder: (BuildContext context) {
45-
return Text('1 ${GoRouterState.of(context).location}');
45+
return Text('1 ${GoRouterState.of(context).uri}');
4646
});
4747
},
4848
routes: <GoRoute>[
4949
GoRoute(
5050
path: 'a',
5151
builder: (_, __) {
5252
return Builder(builder: (BuildContext context) {
53-
return Text('2 ${GoRouterState.of(context).location}');
53+
return Text('2 ${GoRouterState.of(context).uri}');
5454
});
5555
}),
5656
]),
@@ -74,7 +74,7 @@ void main() {
7474
path: '/',
7575
builder: (_, __) {
7676
return Builder(builder: (BuildContext context) {
77-
return Text('1 ${GoRouterState.of(context).location}');
77+
return Text('1 ${GoRouterState.of(context).uri}');
7878
});
7979
},
8080
routes: <GoRoute>[
@@ -110,15 +110,16 @@ void main() {
110110
path: '/',
111111
builder: (_, __) {
112112
return Builder(builder: (BuildContext context) {
113-
return Text(GoRouterState.of(context).location);
113+
return Text(GoRouterState.of(context).uri.toString());
114114
});
115115
},
116116
routes: <GoRoute>[
117117
GoRoute(
118118
path: 'a',
119119
builder: (_, __) {
120120
return Builder(builder: (BuildContext context) {
121-
return Text(key: key, GoRouterState.of(context).location);
121+
return Text(
122+
key: key, GoRouterState.of(context).uri.toString());
122123
});
123124
}),
124125
]),
@@ -152,15 +153,16 @@ void main() {
152153
path: '/',
153154
builder: (_, __) {
154155
return Builder(builder: (BuildContext context) {
155-
return Text(GoRouterState.of(context).location);
156+
return Text(GoRouterState.of(context).uri.toString());
156157
});
157158
},
158159
routes: <GoRoute>[
159160
GoRoute(
160161
path: 'a',
161162
builder: (_, __) {
162163
return Builder(builder: (BuildContext context) {
163-
return Text(key: key, GoRouterState.of(context).location);
164+
return Text(
165+
key: key, GoRouterState.of(context).uri.toString());
164166
});
165167
}),
166168
]),

0 commit comments

Comments
 (0)