-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
flutter/packages
#8889Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listp: go_router_builderThe go_router_builder packageThe go_router_builder packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
Steps to reproduce
- Generate code for sample class below
- Dart analyze will show "The '!' will have no effect because the receiver can't be null."
This also happens in 2.8.2:
Expected results
Generated code does not show a warning in dart analyzer.
Code emitted should be int.parse(state.pathParameters['id']!) because the parameter is not nullable.
Actual results
Generated code is "int.parse()!", but parse() can never be null.
So dart correctly generates this warning:
The '!' will have no effect because the receiver can't be null.
Try removing the '!' operator.
extension $MyRouteExtension on MyRoute {
static MyRoute _fromState(GoRouterState state) =>
MyRoute(int.parse(state.pathParameters['id']!)!);
String get location => GoRouteData.$location(
'/product/${Uri.encodeComponent(id.toString())}',
);
void go(BuildContext context) => context.go(location);
Future<T?> push<T>(BuildContext context) => context.push<T>(location);
void pushReplacement(BuildContext context) =>
context.pushReplacement(location);
void replace(BuildContext context) => context.replace(location);
}Code sample
Code sample
TypedGoRoute<MyRoute>(path: '/product/:id'),
class MyRoute extends GoRouteData {
final int id;
const MyRoute (this.id);
@override
Widget build(BuildContext context, GoRouterState state) {
return SomeScreen(productId: id);
}
}Flutter Doctor output
Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.29.0, on Microsoft Windows [Version 10.0.26100.3194], locale de-DE)
[√] Windows Version (11 Pro 64-bit, 24H2, 2009)
[√] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.12.4)
[√] Android Studio (version 2024.2)
[√] VS Code, 64-bit edition (version 1.97.2)
[√] Connected device (4 available)
[√] Network resourcesoffich
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listp: go_router_builderThe go_router_builder packageThe go_router_builder packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team