no_ dynamic_ casts
Learn about the no_dynamic_casts linter rule.
Avoid implicit casts from dynamic.
Details
#DO avoid implicit casts from dynamic.
Assigning a dynamic-typed expression to a non-dynamic, non-Object?
target is a form of implicit casting. It is better to make such a cast
explicit, so that it is visible to developers.
BAD:
void f(dynamic x) {
int y = x;
}
GOOD:
void f(dynamic x) {
int y = x as int;
}
Enable
#
To enable the no_dynamic_casts rule, add no_dynamic_casts under
linter > rules in your analysis_options.yaml
file:
linter:
rules:
- no_dynamic_casts
If you're instead using the YAML map syntax to configure linter rules,
add no_dynamic_casts: true under linter > rules:
linter:
rules:
no_dynamic_casts: true
Unless stated otherwise, the documentation on this site reflects Dart 3.12.2. Report an issue.