avoid_ annotating_ with_ dynamic
Learn about the avoid_annotating_with_dynamic linter rule.
Avoid annotating with dynamic when not required.
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:
dynamic lookUpOrDefault(String name, Map map, dynamic defaultValue) {
var value = map[name];
if (value != null) return value;
return defaultValue;
}
GOOD:
lookUpOrDefault(String name, Map map, defaultValue) {
var value = map[name];
if (value != null) return value;
return defaultValue;
}
Enable
#
To enable the avoid_annotating_with_dynamic rule,
add avoid_annotating_with_dynamic
under
linter > rules in your
analysis_options.yaml
file:
linter:
rules:
- avoid_annotating_with_dynamic
If you're instead using the YAML map syntax to configure
linter rules, add
avoid_annotating_with_dynamic: true under
linter > rules:
linter:
rules:
avoid_annotating_with_dynamic: true
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.