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:
void f(int Function() first, int Function() second) {
first() + second();
}
Common fixes
#If the expression doesn't need to be computed, then remove it:
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:
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:
void f(int Function() first, int Function() second) {
first();
second();
}
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.