Contents

use_if_null_to_convert_nulls_to_bools

Contents

Use ?? operators to convert nulls to bools.

This rule is available as of Dart 2.13.

Details

#

From Effective Dart:

Use ?? operators to convert nulls to bools.

BAD:

dart
if (nullableBool == true) {
}
if (nullableBool != false) {
}

GOOD:

dart
if (nullableBool ?? false) {
}
if (nullableBool ?? true) {
}

Usage

#

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