目錄
目錄

Use if-null operators to convert nulls to bools.

This rule is available as of Dart 2.13.0.

Details

From Effective Dart:

Use if-null operators to convert nulls to bools.

BAD:

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

GOOD:

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:

linter:
  rules:
    - use_if_null_to_convert_nulls_to_bools