Skip to content

Commit 9c592e0

Browse files
authored
[go_router_builder] Support go_router v7 (#3858)
#3819 Fixed go_router_builder to generate code for go_router v7.0.0.
1 parent 0a12f2c commit 9c592e0

11 files changed

+78
-61
lines changed

packages/go_router_builder/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.0.0
2+
3+
* Updates the documentation to go_router v7.0.0.
4+
* Bumps go_router version in example folder to v7.0.0.
5+
16
## 1.2.2
27

38
* Supports returning value in generated `push` method. [go_router CHANGELOG](https://github.com/flutter/packages/blob/main/packages/go_router/CHANGELOG.md#650)

packages/go_router_builder/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ To use `go_router_builder`, you need to have the following dependencies in
88
```yaml
99
dependencies:
1010
# ...along with your other dependencies
11-
go_router: ^3.1.0
11+
go_router: ^7.0.0
1212

1313
dev_dependencies:
1414
# ...along with your other dev-dependencies
1515
build_runner: ^2.0.0
16-
go_router_builder: ^1.0.0
16+
go_router_builder: ^2.0.0
1717
```
1818
1919
### Source code
@@ -46,7 +46,7 @@ Read more about using
4646
in a URI format into one or more page builders, each that require zero or more
4747
arguments that are passed as path and query parameters as part of the location.
4848
`go_router` does a good job of making the path and query parameters available
49-
via the `params` and `queryParams` properties of the `GoRouterState` object, but
49+
via the `pathParameters` and `queryParameters` properties of the `GoRouterState` object, but
5050
often the page builder must first parse the parameters into types that aren't
5151
`String`s, e.g.
5252

@@ -55,7 +55,7 @@ GoRoute(
5555
path: ':authorId',
5656
builder: (context, state) {
5757
// require the authorId to be present and be an integer
58-
final authorId = int.parse(state.params['authorId']!);
58+
final authorId = int.parse(state.pathParameters['authorId']!);
5959
return AuthorDetailsScreen(authorId: authorId);
6060
},
6161
),
@@ -258,8 +258,8 @@ generator:
258258
```dart
259259
redirect: (state) {
260260
final loggedIn = loginInfo.loggedIn;
261-
final loggingIn = state.subloc == LoginRoute().location;
262-
if( !loggedIn && !loggingIn ) return LoginRoute(from: state.subloc).location;
261+
final loggingIn = state.matchedLocation == LoginRoute().location;
262+
if( !loggedIn && !loggingIn ) return LoginRoute(from: state.matchedLocation).location;
263263
if( loggedIn && loggingIn ) return HomeRoute().location;
264264
return null;
265265
}
@@ -280,7 +280,7 @@ class HomeRoute extends GoRouteData {
280280
## Type conversions
281281

282282
The code generator can convert simple types like `int` and `enum` to/from the
283-
`String` type of the underlying params:
283+
`String` type of the underlying pathParameters:
284284

285285
```dart
286286
enum BookKind { all, popular, recent }

packages/go_router_builder/example/lib/all_types.g.dart

Lines changed: 42 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/go_router_builder/example/lib/main.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ class App extends StatelessWidget {
4040
redirect: (BuildContext context, GoRouterState state) {
4141
final bool loggedIn = loginInfo.loggedIn;
4242

43-
// check just the subloc in case there are query parameters
43+
// check just the matchedLocation in case there are query parameters
4444
final String loginLoc = const LoginRoute().location;
45-
final bool goingToLogin = state.subloc == loginLoc;
45+
final bool goingToLogin = state.matchedLocation == loginLoc;
4646

4747
// the user is not logged in and not headed to /login, they need to login
4848
if (!loggedIn && !goingToLogin) {
49-
return LoginRoute(fromPage: state.subloc).location;
49+
return LoginRoute(fromPage: state.matchedLocation).location;
5050
}
5151

5252
// the user is logged in and headed to /login, no need to login again

packages/go_router_builder/example/lib/main.g.dart

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/go_router_builder/example/lib/shell_route_with_keys_example.g.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/go_router_builder/example/lib/simple_example.g.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/go_router_builder/example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ environment:
88
dependencies:
99
flutter:
1010
sdk: flutter
11-
go_router: ^6.2.0
11+
go_router: ^7.0.0
1212
provider: 6.0.5
1313

1414
dev_dependencies:

packages/go_router_builder/lib/src/type_helpers.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ String _stateValueAccess(ParameterElement element) {
9898
}
9999

100100
if (element.isRequired) {
101-
return 'params[${escapeDartString(element.name)}]!';
101+
return 'pathParameters[${escapeDartString(element.name)}]!';
102102
}
103103

104104
if (element.isOptional) {
105-
return 'queryParams[${escapeDartString(element.name.kebab)}]';
105+
return 'queryParameters[${escapeDartString(element.name.kebab)}]';
106106
}
107107

108108
throw InvalidGenerationSourceError(
@@ -329,7 +329,7 @@ abstract class _TypeHelperWithHelper extends _TypeHelper {
329329
if (!parameterElement.isRequired) {
330330
return '$convertMapValueHelperName('
331331
'${escapeDartString(parameterElement.name.kebab)}, '
332-
'state.queryParams, '
332+
'state.queryParameters, '
333333
'${helperName(paramType)})';
334334
}
335335
return '${helperName(paramType)}'

packages/go_router_builder/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: go_router_builder
22
description: >-
33
A builder that supports generated strongly-typed route helpers for
44
package:go_router
5-
version: 1.2.2
5+
version: 2.0.0
66
repository: https://github.com/flutter/packages/tree/main/packages/go_router_builder
77
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router_builder%22
88

@@ -23,6 +23,6 @@ dependencies:
2323

2424
dev_dependencies:
2525
build_runner: ^2.0.0
26-
go_router: ^6.0.10
26+
go_router: ^7.0.0
2727
source_gen_test: ^1.0.0
2828
test: ^1.20.0

packages/go_router_builder/test/test_inputs/_go_router_builder_test_input.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ RouteBase get $enumParam => GoRouteData.$route(
7070
7171
extension $EnumParamExtension on EnumParam {
7272
static EnumParam _fromState(GoRouterState state) => EnumParam(
73-
y: _$EnumTestEnumMap._$fromName(state.params['y']!),
73+
y: _$EnumTestEnumMap._$fromName(state.pathParameters['y']!),
7474
);
7575
7676
String get location => GoRouteData.$location(
@@ -119,7 +119,8 @@ RouteBase get $defaultValueRoute => GoRouteData.$route(
119119
120120
extension $DefaultValueRouteExtension on DefaultValueRoute {
121121
static DefaultValueRoute _fromState(GoRouterState state) => DefaultValueRoute(
122-
param: _$convertMapValue('param', state.queryParams, int.parse) ?? 0,
122+
param:
123+
_$convertMapValue('param', state.queryParameters, int.parse) ?? 0,
123124
);
124125
125126
String get location => GoRouteData.$location(
@@ -160,7 +161,8 @@ RouteBase get $extraValueRoute => GoRouteData.$route(
160161
161162
extension $ExtraValueRouteExtension on ExtraValueRoute {
162163
static ExtraValueRoute _fromState(GoRouterState state) => ExtraValueRoute(
163-
param: _$convertMapValue('param', state.queryParams, int.parse) ?? 0,
164+
param:
165+
_$convertMapValue('param', state.queryParameters, int.parse) ?? 0,
164166
$extra: state.extra as int?,
165167
);
166168

0 commit comments

Comments
 (0)