Skip to content

[go_router_builder]Update the way to pass the extra param in router_config #3005

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 13 commits into from
Feb 27, 2023
4 changes: 4 additions & 0 deletions packages/go_router_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.3

* Updates router_config to not passing itself as `extra`.

## 1.1.2

* Adds support for Iterables, Lists and Sets in query params for TypedGoRoute. [#108437](https://github.com/flutter/flutter/issues/108437).
Expand Down
72 changes: 36 additions & 36 deletions packages/go_router_builder/example/lib/all_types.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions packages/go_router_builder/example/lib/main.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions packages/go_router_builder/example/lib/simple_example.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions packages/go_router_builder/lib/src/route_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,14 @@ extension $_extensionName on $_className {

String get location => GoRouteData.\$location($_locationArgs,$_locationQueryParams);

void go(BuildContext context) => context.go(location, extra: this);
void go(BuildContext context) =>
context.go(location${_extraParam != null ? ', extra: $extraFieldName' : ''});

void push(BuildContext context) => context.push(location, extra: this);
void push(BuildContext context) =>
context.push(location${_extraParam != null ? ', extra: $extraFieldName' : ''});

void pushReplacement(BuildContext context) =>
context.pushReplacement(location, extra: this);
context.pushReplacement(location${_extraParam != null ? ', extra: $extraFieldName' : ''});
}
''';

Expand Down Expand Up @@ -188,14 +190,16 @@ GoRoute get $_routeGetterName => ${_routeDefinition()};
}
}

ParameterElement? get _extraParam => _ctor.parameters
.singleWhereOrNull((ParameterElement element) => element.isExtraField);

String get _newFromState {
final StringBuffer buffer = StringBuffer('=>');
if (_ctor.isConst && _ctorParams.isEmpty && _ctorQueryParams.isEmpty) {
buffer.writeln('const ');
}

final ParameterElement? extraParam = _ctor.parameters
.singleWhereOrNull((ParameterElement element) => element.isExtraField);
final ParameterElement? extraParam = _extraParam;

buffer.writeln('$_className(');
for (final ParameterElement param in <ParameterElement>[
Expand Down
2 changes: 1 addition & 1 deletion packages/go_router_builder/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: go_router_builder
description: >-
A builder that supports generated strongly-typed route helpers for
package:go_router
version: 1.1.2
version: 1.1.3
repository: https://github.com/flutter/packages/tree/main/packages/go_router_builder
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router_builder%22

Expand Down
1 change: 1 addition & 0 deletions packages/go_router_builder/test/builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const Set<String> _expectedAnnotatedTests = <String>{
'AppliedToWrongClassType',
'BadPathParam',
'ExtraMustBeOptional',
'ExtraValueRoute',
'MissingPathParam',
'MissingPathValue',
'MissingTypeAnnotation',
Expand Down
Loading