Skip to main content

prefer-typedefs-for-callbacks

added in: 1.11.0
⚙️
Pro+

Warns when a Function type is declared not as a typedef.

⚙️ Config

Set ignore-fields (default is false) to exclude fields from the check.

Set ignore-parameters (default is false) to exclude parameters from the check.

Set ignore-type-arguments (default is false) to exclude type arguments from the check.

Set ignore-return-types (default is false) to exclude return types from the check.

dart_code_metrics:
...
rules:
...
- prefer-typedefs-for-callbacks:
ignore-fields: false
ignore-parameters: false
ignore-type-arguments: false
ignore-return-types: false

Example

❌ Bad:

class SomeWidget {
final void Function() onEnterButton; // LINT

const SomeWidget(
this.onEnterButton,
);

void another({
void Function()? onRemoved, // LINT
}) {}
}

✅ Good:

class SomeWidget {
final VoidCallback onEnterButton;

const SomeWidget(
this.onEnterButton,
);

void another({
VoidCallback? onRemoved,
}) {}
}