unnecessary_statements
Unnecessary statement.
Description
#The analyzer produces this diagnostic when an expression statement has no clear effect.
Example
#The following code produces this diagnostic because the addition of the returned values from the two invocations has no clear effect:
dart
void f(int Function() first, int Function() second) {
first() + second();
}
Common fixes
#If the expression doesn't need to be computed, then remove it:
dart
void f(int Function() first, int Function() second) {
}
If the value of the expression is needed, then make use of it, possibly assigning it to a local variable first:
dart
void f(int Function() first, int Function() second) {
print(first() + second());
}
If portions of the expression need to be executed, then remove the unnecessary portions:
dart
void f(int Function() first, int Function() second) {
first();
second();
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。