avoid-missed-calls
preset: recommended
Warns when a method that should be invoked is passed as tear-off.
Missed invocations are usually a sign of a bug and can lead to unexpected results.
Example
❌ Bad:
String _strHandle() => 'Hi!';
void main() {
SomeClass(
// LINT: This identifier is expected to be an invocation. Try adding ().
callback: () async => _handle,
// LINT: This identifier is expected to be an invocation. Try adding ().
regular: () => _handle,
another: _strHandle,
);
}
class SomeClass {
final Future<void> Function() callback;
final void Function() regular;
final String Function() another;
const SomeClass({
required this.callback,
required this.regular,
required this.another,
});
}
void _handle() {
...
}
✅ Good:
void main() {
SomeClass(
callback: () async => _handle(), // Correct, invoked
regular: () => _handle(), // Correct, invoked
another: _strHandle, // Correct, passed as tear-off
);
}