avoid_dynamic

SeverityQuick FixOptions
Info

Details

DO avoid using the dynamic type unnecessarily.

While the dynamic type can be useful in certain scenarios, it sacrifices the benefits of static typing and decreases code readability.

Using dynamic with Map will not trigger the lint.
Bad
dynamic thing = 'text';
void log(dynamic something) => print(something);
List<dynamic> list = [1, 2, 3];
final setLiteral = <dynamic>{'a', 'b', 'c'};
Good
String thing = 'text';
void log(String something) => print(something);
List<int> list = [1, 2, 3];
final setLiteral = <String>{'a', 'b', 'c'};

Usage

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

custom_lint:
  rules:
    - avoid_dynamic