Skip to main content

prefer-typedefs-for-callbacks

added in: 1.11.0

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

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,
}) {}
}