avoid_annotating_with_dynamic
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:
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;
}
Enable
#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
If you're instead using the YAML map syntax to configure linter rules, add avoid_annotating_with_dynamic: true
under linter > rules:
analysis_options.yaml
yaml
linter:
rules:
avoid_annotating_with_dynamic: true
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-03-07. View source or report an issue.