dart-fix-runtime-errors
Installation
SKILL.md
Resolving Dart Static Analysis Errors
Contents
Core Concepts & Guidelines
Type System & Soundness
Enforce Dart's sound type system to prevent runtime invalid states.
- Method Overrides: Maintain sound return types (covariant) and parameter types (contravariant). Never tighten a parameter type in a subclass unless explicitly marked with the
covariantkeyword. - Generics & Collections: Add explicit type annotations to generic classes (e.g.,
List<T>,Map<K, V>). Never assign aList<dynamic>to a typed list (e.g.,List<Cat>). - Downcasting: Avoid implicit downcasts from
dynamic. Use explicit casts (e.g.,as List<Cat>) when necessary, but ensure the underlying runtime type matches to preventTypeErrorexceptions. - Strict Casts: Enable
strict-casts: trueinanalysis_options.yamlunderanalyzer: language:to force explicit casting and catch implicit downcast errors at compile time.