目錄
目錄

Unnecessary null checks.

This rule is currently experimental and available as of Dart 2.12.0.

This rule has a quick fix available.

Details

DON’T apply a null check when a nullable value is accepted.

BAD:

f(int? i) {}
m() {
  int? j;
  f(j!);
}

GOOD:

f(int? i) {}
m() {
  int? j;
  f(j);
}

Usage

To enable the unnecessary_null_checks rule, add unnecessary_null_checks under linter > rules in your analysis_options.yaml file:

linter:
  rules:
    - unnecessary_null_checks