prefer-correct-callback-field-name
Warns when a field with a Function type does not matched the configured name or a field with a non-Function type matches the configured name.
note
This rule does not take _
into account when checking the name.
⚙️ Config
Set name-pattern
(default is ^on[A-Z]+
) to set the expected field name.
dart_code_metrics:
...
rules:
...
- prefer-correct-callback-field-name:
name-pattern: ^on[A-Z]+
Example
❌ Bad:
class SomeWidget {
final String onSome; // LINT
final Function doWork; // LINT
const SomeWidget(this.onSome, this.doWork);
}
✅ Good:
class SomeWidget {
final String value;
final Function onTap;
const SomeWidget(this.value, this.onTap);
}