目錄
目錄

Specify @required on named parameters without defaults.

This rule is currently deprecated and available as of Dart 2.0.0.

This rule has a quick fix available.

Details

DO specify @required on named parameters without a default value on which an assert(param != null) is done.

BAD:

m1({a}) {
  assert(a != null);
}

GOOD:

m1({@required a}) {
  assert(a != null);
}

m2({a: 1}) {
  assert(a != null);
}

NOTE: Only asserts at the start of the bodies will be taken into account.

Usage

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

linter:
  rules:
    - always_require_non_null_named_parameters