Skip to main content

default_value_on_required_parameter

Required named parameters can't have a default value.

Description

#

The analyzer produces this diagnostic when a named parameter has both the required modifier and a default value. If the parameter is required, then a value for the parameter is always provided at the call sites, so the default value can never be used.

Example

#

The following code generates this diagnostic:

dart
void log({required String message = 'no message'}) {}

Common fixes

#

If the parameter is really required, then remove the default value:

dart
void log({required String message}) {}

If the parameter isn't always required, then remove the required modifier:

dart
void log({String message = 'no message'}) {}