Skip to main content

avoid_positional_boolean_parameters

Details about the 'avoid_positional_boolean_parameters' diagnostic produced by the Dart analyzer.

'bool' parameters should be named parameters.

Description

#

The analyzer produces this diagnostic when a non-overriding, public function has a positional parameter of type bool.

Positional boolean parameters can cause ambiguity when the function is invoked because the function of the specified boolean value might not be clear from the value alone. Named parameters make their intent explicit.

Example

#

The following code produces this diagnostic because the function f has a positional parameter with a type of bool:

dart
void f(bool b) {}

Common fixes

#

Convert the positional parameter to a named parameter:

dart
void f({bool b = false}) {}