Skip to content

[go_router_builder] Fixes an deprecated warning for using withNullability #9158

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

Merged
Show file tree
Hide file tree
Changes from all 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.9.1

- Fixes an deprecated warning for using withNullability

## 2.9.0

- Adds support for `caseSensitive` for go routes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:build/build.dart';
import 'package:source_gen/source_gen.dart';

import 'route_config.dart';
import 'type_helpers.dart';

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

Expand Down Expand Up @@ -79,7 +80,7 @@ ${getters.map((String e) => "$e,").join('\n')}
ConstantReader annotation,
) {
final String typedAnnotation =
annotation.objectValue.type!.getDisplayString(withNullability: false);
withoutNullability(annotation.objectValue.type!.getDisplayString());
final String type =
typedAnnotation.substring(0, typedAnnotation.indexOf('<'));
final String routeData = _annotations[type]!;
Expand Down
3 changes: 2 additions & 1 deletion packages/go_router_builder/lib/src/route_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class StatefulShellBranchConfig extends RouteBaseConfig {

@override
String get factorConstructorParameters => '';

@override
String get routeConstructorParameters =>
'${navigatorKey == null ? '' : 'navigatorKey: $navigatorKey,'}'
Expand Down Expand Up @@ -616,7 +617,7 @@ abstract class RouteBaseConfig {
return false;
}
final DartType typeArgument = typeArguments.single;
if (typeArgument.getDisplayString(withNullability: false) !=
if (withoutNullability(typeArgument.getDisplayString()) !=
'NavigatorState') {
return false;
}
Expand Down
14 changes: 12 additions & 2 deletions packages/go_router_builder/lib/src/type_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ String decodeParameter(ParameterElement element, Set<String> pathParameters) {

throw InvalidGenerationSourceError(
'The parameter type '
'`${paramType.getDisplayString(withNullability: false)}` is not supported.',
'`${withoutNullability(paramType.getDisplayString())}` is not supported.',
element: element,
);
}
Expand Down Expand Up @@ -111,7 +111,7 @@ String enumMapName(InterfaceType type) => '_\$${type.element.name}EnumMap';
String _stateValueAccess(ParameterElement element, Set<String> pathParameters) {
if (element.isExtraField) {
// ignore: avoid_redundant_argument_values
return 'extra as ${element.type.getDisplayString(withNullability: true)}';
return 'extra as ${element.type.getDisplayString()}';
}

late String access;
Expand All @@ -127,6 +127,16 @@ String _stateValueAccess(ParameterElement element, Set<String> pathParameters) {
return access;
}

/// Returns `true` if the type string ends with a nullability marker (`?` or `*`)
bool _isNullableType(String type) {
return type.endsWith('?') || type.endsWith('*');
}

/// Returns the type string without a trailing nullability marker
String withoutNullability(String type) {
return _isNullableType(type) ? type.substring(0, type.length - 1) : type;
}

abstract class _TypeHelper {
const _TypeHelper();

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