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
:
void f({int? y, required int x}) {}
Common fixes
#Reorder the parameters so that all required named parameters are before any optional named parameters:
void f({required int x, int? y}) {}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.