Contents

avoid_annotating_with_dynamic

Contents

Avoid annotating with dynamic when not required.

This rule is available as of Dart 2.0.

This rule has a quick fix available.

Details

#

AVOID annotating with dynamic when not required.

As dynamic is the assumed return value of a function or method, it is usually not necessary to annotate it.

BAD:

dart
dynamic lookUpOrDefault(String name, Map map, dynamic defaultValue) {
  var value = map[name];
  if (value != null) return value;
  return defaultValue;
}

GOOD:

dart
lookUpOrDefault(String name, Map map, defaultValue) {
  var value = map[name];
  if (value != null) return value;
  return defaultValue;
}

Usage

#

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

analysis_options.yaml
yaml
linter:
  rules:
    - avoid_annotating_with_dynamic