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.7.2. Page last updated on 2025-03-07. View source or report an issue.