Skip to content
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

[go_router_builder]Avoid losing NullabilitySuffix for typeArguments #5215

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
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 @@
## 2.3.4

* Fixes a bug of typeArguments losing NullabilitySuffix

## 2.3.3

* Adds `initialLocation` for `StatefulShellBranchConfig`
Expand Down
2 changes: 1 addition & 1 deletion packages/go_router_builder/lib/src/type_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ String enumMapName(InterfaceType type) => '_\$${type.element.name}EnumMap';

String _stateValueAccess(ParameterElement element, Set<String> pathParameters) {
if (element.isExtraField) {
return 'extra as ${element.type.getDisplayString(withNullability: element.isOptional)}';
return 'extra as ${element.type.getDisplayString(withNullability: true)}';
}

late String access;
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: 2.3.3
version: 2.3.4
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:go_router/go_router.dart';

@TypedGoRoute<RequiredNullableTypeArgumentsExtraValueRoute>(path: '/default-value-route')
class RequiredNullableTypeArgumentsExtraValueRoute extends GoRouteData {
RequiredNullableTypeArgumentsExtraValueRoute({required this.$extra});
final List<int?> $extra;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
RouteBase get $requiredNullableTypeArgumentsExtraValueRoute =>
GoRouteData.$route(
path: '/default-value-route',
factory:
$RequiredNullableTypeArgumentsExtraValueRouteExtension._fromState,
);

extension $RequiredNullableTypeArgumentsExtraValueRouteExtension
on RequiredNullableTypeArgumentsExtraValueRoute {
static RequiredNullableTypeArgumentsExtraValueRoute _fromState(
GoRouterState state) =>
RequiredNullableTypeArgumentsExtraValueRoute(
$extra: state.extra as List<int?>,
);

String get location => GoRouteData.$location(
'/default-value-route',
);

void go(BuildContext context) => context.go(location, extra: $extra);

Future<T?> push<T>(BuildContext context) =>
context.push<T>(location, extra: $extra);

void pushReplacement(BuildContext context) =>
context.pushReplacement(location, extra: $extra);

void replace(BuildContext context) =>
context.replace(location, extra: $extra);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

a newline at the end

Copy link
Member Author

Choose a reason for hiding this comment

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

done