avoid_annotating_with_dynamic
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
除非另有说明,文档之所提及适用于 Dart 3.5.4 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。