Skip to content

Commit

Permalink
[go_router_builder]Avoid losing NullabilitySuffix for typeArguments (#…
Browse files Browse the repository at this point in the history
…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].*
  • Loading branch information
yiiim authored Oct 26, 2023
1 parent 9e4ca6b commit 45ed8c9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
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,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<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);
}

0 comments on commit 45ed8c9

Please sign in to comment.