Skip to main content

always_put_required_named_parameters_first

Required named parameters should be before optional named parameters.

Description

#

The analyzer produces this diagnostic when required named parameters occur after optional named parameters.

Example

#

The following code produces this diagnostic because the required parameter x is after the optional parameter y:

dart
void f({int? y, required int x}) {}

Common fixes

#

Reorder the parameters so that all required named parameters are before any optional named parameters:

dart
void f({required int x, int? y}) {}