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:
dart
f(String? key) => {if (key != null) key: "value"};
GOOD:
dart
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:
analysis_options.yaml
yaml
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:
analysis_options.yaml
yaml
linter:
rules:
use_null_aware_elements: true
Was this page's content helpful?
除非另有说明,文档之所提及适用于 Dart 3.9.2 版本报告页面问题。