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:
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:
extension E on int? {
int m() => 1;
}
int? f(int? i) => i.m();
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.