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();
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。