unnecessary_lambdas
Closure should be a tearoff.
Description
#The analyzer produces this diagnostic when a closure (lambda) could be replaced by a tear-off.
Example
#The following code produces this diagnostic because the closure passed to
forEach
contains only an invocation of the function print
with the
parameter of the closure:
dart
void f(List<String> strings) {
strings.forEach((string) {
print(string);
});
}
Common fixes
#Replace the closure with a tear-off of the function or method being invoked with the closure:
dart
void f(List<String> strings) {
strings.forEach(print);
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。