prefer_explicit_parameter_names
This rule flags a function type — in a typedef or a function-typed parameter — that declares unnamed parameters.
This rule is in the pedantic preset.
Why use this rule
Section titled “Why use this rule”void Function(String, int) tells a reader the types and nothing else. At the point where someone writes the callback, (String, int) gives them two anonymous values to guess at — is the int an index, a count, an id?
void Function(String label, int count) answers that in the signature, where the answer belongs, and IDEs echo those names into the closure they generate.
A single-parameter function type is exempt by default: void Function(T) is unambiguous from the type alone, and naming it adds nothing.
See also: Effective Dart: type annotations
typedef OnChanged = void Function(String, int);
void listen(void Function(String, int) callback) {}typedef OnChanged = void Function(String label, int count);
void listen(void Function(String label, int count) callback) {}
// Exempt by default — unambiguous from the type alone.typedef OnTap = void Function(String);Options
Section titled “Options”many_lints: rules: prefer_explicit_parameter_names: min_parameters: 2rules: prefer_explicit_parameter_names: min_parameters: 2| Option | Type | Default | Description |
|---|---|---|---|
min_parameters |
int | 2 |
Fewest parameters a function type must have before names are required |
Turning this rule off
Section titled “Turning this rule off”To disable this rule:
rules: prefer_explicit_parameter_names: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”prefer_explicit_function_type— Prefer explicit function type annotations over the bare ‘Function’ type.prefer_typedefs_for_callbacks— Name a multi-parameter function type with a typedef.prefer_void_callback— Use ‘VoidCallback’ instead of ‘void Function()’.prefer_explicit_type_arguments— Pin the type arguments of the APIs where inference surprises.