always_require_non_null_named_parameters
Specify @required
on named parameters without defaults.
Details
#NOTE: This rule is removed in Dart 3.3.0; it is no longer functional.
DO specify @required
on named parameters without a default value on which an assert(param != null)
is done.
BAD:
m1({a}) {
assert(a != null);
}
GOOD:
m1({@required a}) {
assert(a != null);
}
m2({a: 1}) {
assert(a != null);
}
NOTE: Only asserts at the start of the bodies will be taken into account.
Enable
#To enable the always_require_non_null_named_parameters
rule, add always_require_non_null_named_parameters
under linter > rules in your analysis_options.yaml
file:
linter:
rules:
- always_require_non_null_named_parameters
If you're instead using the YAML map syntax to configure linter rules, add always_require_non_null_named_parameters: true
under linter > rules:
linter:
rules:
always_require_non_null_named_parameters: true
Unless stated otherwise, the documentation on this site reflects Dart 3.6.0. Page last updated on 2025-01-27. View source or report an issue.