Skip to content

Commit 45ed8c9

Browse files
authored
[go_router_builder]Avoid losing NullabilitySuffix for typeArguments (flutter#5215)
fixes 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].*
1 parent 9e4ca6b commit 45ed8c9

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

packages/go_router_builder/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.3.4
2+
3+
* Fixes a bug of typeArguments losing NullabilitySuffix
4+
15
## 2.3.3
26

37
* Adds `initialLocation` for `StatefulShellBranchConfig`

packages/go_router_builder/lib/src/type_helpers.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ String enumMapName(InterfaceType type) => '_\$${type.element.name}EnumMap';
9494

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

100100
late String access;

packages/go_router_builder/pubspec.yaml

Lines changed: 1 addition & 1 deletion
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: 2.3.3
5+
version: 2.3.4
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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:go_router/go_router.dart';
6+
7+
@TypedGoRoute<RequiredNullableTypeArgumentsExtraValueRoute>(
8+
path: '/default-value-route')
9+
class RequiredNullableTypeArgumentsExtraValueRoute extends GoRouteData {
10+
RequiredNullableTypeArgumentsExtraValueRoute({required this.$extra});
11+
final List<int?> $extra;
12+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
RouteBase get $requiredNullableTypeArgumentsExtraValueRoute =>
2+
GoRouteData.$route(
3+
path: '/default-value-route',
4+
factory:
5+
$RequiredNullableTypeArgumentsExtraValueRouteExtension._fromState,
6+
);
7+
8+
extension $RequiredNullableTypeArgumentsExtraValueRouteExtension
9+
on RequiredNullableTypeArgumentsExtraValueRoute {
10+
static RequiredNullableTypeArgumentsExtraValueRoute _fromState(
11+
GoRouterState state) =>
12+
RequiredNullableTypeArgumentsExtraValueRoute(
13+
$extra: state.extra as List<int?>,
14+
);
15+
16+
String get location => GoRouteData.$location(
17+
'/default-value-route',
18+
);
19+
20+
void go(BuildContext context) => context.go(location, extra: $extra);
21+
22+
Future<T?> push<T>(BuildContext context) =>
23+
context.push<T>(location, extra: $extra);
24+
25+
void pushReplacement(BuildContext context) =>
26+
context.pushReplacement(location, extra: $extra);
27+
28+
void replace(BuildContext context) =>
29+
context.replace(location, extra: $extra);
30+
}

0 commit comments

Comments
 (0)