From 55ec89cf1a7e745015a698164571492c454a268a Mon Sep 17 00:00:00 2001 From: yim Date: Fri, 27 Oct 2023 01:17:12 +0800 Subject: [PATCH] [go_router_builder]Avoid losing NullabilitySuffix for typeArguments (#5215) fixes flutter/flutter#135591 *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* --- packages/go_router_builder/CHANGELOG.md | 4 +++ .../lib/src/type_helpers.dart | 2 +- packages/go_router_builder/pubspec.yaml | 2 +- ...d_nullable_type_arguments_extra_value.dart | 12 ++++++++ ...ble_type_arguments_extra_value.dart.expect | 30 +++++++++++++++++++ 5 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 packages/go_router_builder/test_inputs/required_nullable_type_arguments_extra_value.dart create mode 100644 packages/go_router_builder/test_inputs/required_nullable_type_arguments_extra_value.dart.expect diff --git a/packages/go_router_builder/CHANGELOG.md b/packages/go_router_builder/CHANGELOG.md index 2afdfb41d0f0..1a647649152f 100644 --- a/packages/go_router_builder/CHANGELOG.md +++ b/packages/go_router_builder/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.3.4 + +* Fixes a bug of typeArguments losing NullabilitySuffix + ## 2.3.3 * Adds `initialLocation` for `StatefulShellBranchConfig` diff --git a/packages/go_router_builder/lib/src/type_helpers.dart b/packages/go_router_builder/lib/src/type_helpers.dart index bd8cc7f31d1b..b17e88b2d52e 100644 --- a/packages/go_router_builder/lib/src/type_helpers.dart +++ b/packages/go_router_builder/lib/src/type_helpers.dart @@ -94,7 +94,7 @@ String enumMapName(InterfaceType type) => '_\$${type.element.name}EnumMap'; String _stateValueAccess(ParameterElement element, Set pathParameters) { if (element.isExtraField) { - return 'extra as ${element.type.getDisplayString(withNullability: element.isOptional)}'; + return 'extra as ${element.type.getDisplayString(withNullability: true)}'; } late String access; diff --git a/packages/go_router_builder/pubspec.yaml b/packages/go_router_builder/pubspec.yaml index cf48de720f07..b53161dfc351 100644 --- a/packages/go_router_builder/pubspec.yaml +++ b/packages/go_router_builder/pubspec.yaml @@ -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 diff --git a/packages/go_router_builder/test_inputs/required_nullable_type_arguments_extra_value.dart b/packages/go_router_builder/test_inputs/required_nullable_type_arguments_extra_value.dart new file mode 100644 index 000000000000..2d7f8a17ac04 --- /dev/null +++ b/packages/go_router_builder/test_inputs/required_nullable_type_arguments_extra_value.dart @@ -0,0 +1,12 @@ +// 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( + path: '/default-value-route') +class RequiredNullableTypeArgumentsExtraValueRoute extends GoRouteData { + RequiredNullableTypeArgumentsExtraValueRoute({required this.$extra}); + final List $extra; +} diff --git a/packages/go_router_builder/test_inputs/required_nullable_type_arguments_extra_value.dart.expect b/packages/go_router_builder/test_inputs/required_nullable_type_arguments_extra_value.dart.expect new file mode 100644 index 000000000000..9877d353f4df --- /dev/null +++ b/packages/go_router_builder/test_inputs/required_nullable_type_arguments_extra_value.dart.expect @@ -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, + ); + + String get location => GoRouteData.$location( + '/default-value-route', + ); + + void go(BuildContext context) => context.go(location, extra: $extra); + + Future push(BuildContext context) => + context.push(location, extra: $extra); + + void pushReplacement(BuildContext context) => + context.pushReplacement(location, extra: $extra); + + void replace(BuildContext context) => + context.replace(location, extra: $extra); +}