use_if_null_to_convert_nulls_to_bools
Use ??
operators to convert null
s to bool
s.
Details
#From Effective Dart:
Use ??
operators to convert null
s to bool
s.
BAD:
dart
if (nullableBool == true) {
}
if (nullableBool != false) {
}
GOOD:
dart
if (nullableBool ?? false) {
}
if (nullableBool ?? true) {
}
Enable
#To enable the use_if_null_to_convert_nulls_to_bools
rule, add use_if_null_to_convert_nulls_to_bools
under linter > rules in your analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- use_if_null_to_convert_nulls_to_bools
If you're instead using the YAML map syntax to configure linter rules, add use_if_null_to_convert_nulls_to_bools: true
under linter > rules:
analysis_options.yaml
yaml
linter:
rules:
use_if_null_to_convert_nulls_to_bools: true
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-03-07. View source or report an issue.