use_ null_ aware_ elements
If-elements testing for null can be replaced with null-aware elements.
Details
#Where possible, use null-aware elements in collection literals.
BAD:
f(String? key) => {if (key != null) key: "value"};
GOOD:
f(String? key) => {?key: "value"};
Enable
#
To enable the
use_null_aware_elements
rule, add
use_null_aware_elements
under
linter > rules
in your
analysis_options.yaml
file:
linter:
rules:
- use_null_aware_elements
If you're instead using the YAML map syntax to configure linter rules,
add
use_null_aware_elements: true
under
linter > rules:
linter:
rules:
use_null_aware_elements: true
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Report an issue.