unnecessary_null_aware_operator_on_extension_on_nullable
Unnecessary use of a null-aware operator to invoke an extension method on a nullable type.
Description
#The analyzer produces this diagnostic when a null-aware operator is used to invoke an extension method on an extension whose type is nullable.
Example
#The following code produces this diagnostic because the extension method m
is invoked using ?.
when it doesn't need to be:
dart
extension E on int? {
int m() => 1;
}
int? f(int? i) => i?.m();
Common fixes
#If it isn't a requirement not invoke the method when the receiver is null
, then remove the question mark from the invocation:
dart
extension E on int? {
int m() => 1;
}
int? f(int? i) => i.m();
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.