Skip to content

Commit 1578d70

Browse files
[go_router_builder] Fixes an deprecated warning for using withNullability (#9158)
*List which issues are fixed by this PR. You must list at least one issue.* [Issue #166603](flutter/flutter#166603) ## Pre-Review Checklist
1 parent b270eae commit 1578d70

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
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.9.1
2+
3+
- Fixes an deprecated warning for using withNullability
4+
15
## 2.9.0
26

37
- Adds support for `caseSensitive` for go routes.

packages/go_router_builder/lib/src/go_router_generator.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:build/build.dart';
1010
import 'package:source_gen/source_gen.dart';
1111

1212
import 'route_config.dart';
13+
import 'type_helpers.dart';
1314

1415
const String _routeDataUrl = 'package:go_router/src/route_data.dart';
1516

@@ -79,7 +80,7 @@ ${getters.map((String e) => "$e,").join('\n')}
7980
ConstantReader annotation,
8081
) {
8182
final String typedAnnotation =
82-
annotation.objectValue.type!.getDisplayString(withNullability: false);
83+
withoutNullability(annotation.objectValue.type!.getDisplayString());
8384
final String type =
8485
typedAnnotation.substring(0, typedAnnotation.indexOf('<'));
8586
final String routeData = _annotations[type]!;

packages/go_router_builder/lib/src/route_config.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class StatefulShellBranchConfig extends RouteBaseConfig {
172172

173173
@override
174174
String get factorConstructorParameters => '';
175+
175176
@override
176177
String get routeConstructorParameters =>
177178
'${navigatorKey == null ? '' : 'navigatorKey: $navigatorKey,'}'
@@ -616,7 +617,7 @@ abstract class RouteBaseConfig {
616617
return false;
617618
}
618619
final DartType typeArgument = typeArguments.single;
619-
if (typeArgument.getDisplayString(withNullability: false) !=
620+
if (withoutNullability(typeArgument.getDisplayString()) !=
620621
'NavigatorState') {
621622
return false;
622623
}

packages/go_router_builder/lib/src/type_helpers.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ String decodeParameter(ParameterElement element, Set<String> pathParameters) {
6868

6969
throw InvalidGenerationSourceError(
7070
'The parameter type '
71-
'`${paramType.getDisplayString(withNullability: false)}` is not supported.',
71+
'`${withoutNullability(paramType.getDisplayString())}` is not supported.',
7272
element: element,
7373
);
7474
}
@@ -111,7 +111,7 @@ String enumMapName(InterfaceType type) => '_\$${type.element.name}EnumMap';
111111
String _stateValueAccess(ParameterElement element, Set<String> pathParameters) {
112112
if (element.isExtraField) {
113113
// ignore: avoid_redundant_argument_values
114-
return 'extra as ${element.type.getDisplayString(withNullability: true)}';
114+
return 'extra as ${element.type.getDisplayString()}';
115115
}
116116

117117
late String access;
@@ -127,6 +127,16 @@ String _stateValueAccess(ParameterElement element, Set<String> pathParameters) {
127127
return access;
128128
}
129129

130+
/// Returns `true` if the type string ends with a nullability marker (`?` or `*`)
131+
bool _isNullableType(String type) {
132+
return type.endsWith('?') || type.endsWith('*');
133+
}
134+
135+
/// Returns the type string without a trailing nullability marker
136+
String withoutNullability(String type) {
137+
return _isNullableType(type) ? type.substring(0, type.length - 1) : type;
138+
}
139+
130140
abstract class _TypeHelper {
131141
const _TypeHelper();
132142

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.9.0
5+
version: 2.9.1
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

0 commit comments

Comments
 (0)