Skip to main content

prefer-explicit-function-type

added in: 1.11.0
Pro+
preset: recommended

Warns when a Function type does not specify the return type and arguments.

Not specifying the return type and the list of arguments can lead to hard-to-spot bugs since the Function type effectively makes the declaration dynamic and disables type checks.

Example

❌ Bad:

class SomeWidget {
final Function onTap; // LINT: This 'Function' type does not specify a return type or parameter list. Try adding them.

const SomeWidget(this.onTap);
}

✅ Good:

class SomeWidget {
final void Function() onTap;

const SomeWidget(this.onTap);
}