From Dart and Flutter
Fetches Dart runtime stack traces via LSP, locates failing lines, applies fixes, and verifies resolution with hot reload.
How this skill is triggered — by the user, by Claude, or both
Slash command
/dart-flutter:dart-fix-runtime-errorsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
- [Core Concepts & Guidelines](#core-concepts--guidelines)
Enforce Dart's sound type system to prevent runtime invalid states.
covariant keyword.List<T>, Map<K, V>). Never assign a List<dynamic> to a typed list (e.g., List<Cat>).dynamic. Use explicit casts (e.g., as List<Cat>) when necessary, but ensure the underlying runtime type matches to prevent TypeError exceptions.strict-casts: true in analysis_options.yaml under analyzer: language: to force explicit casting and catch implicit downcast errors at compile time.Eliminate static errors related to null safety by correctly managing variable initialization and nullability.
? for nullable types, ! for null assertions, and required for named parameters that cannot be null.late keyword for non-nullable variables guaranteed to be initialized before use. Apply this specifically to top-level or instance variables where Dart's control flow analysis cannot definitively prove initialization._ wildcard variable (Dart 3.7+) for non-binding local variables or parameters to avoid unused variable warnings.Distinguish between recoverable exceptions and unrecoverable errors.
Exception subtypes for recoverable failures.Error or its subtypes (e.g., TypeError, ArgumentError). Errors indicate programming bugs that must be fixed, not caught. Enforce this by enabling the avoid_catching_errors linter rule.rethrow inside a catch block to propagate an exception while preserving its original stack trace.Use this sequential workflow to identify, fix, and verify static analysis errors in a Dart project. Copy the checklist to track your progress.
Task Progress:
1. Run static analyzer Execute the Dart analyzer to identify all static errors in the target directory or file.
dart analyze . --fatal-infos
2. Apply automated fixes
Use the dart fix tool to automatically resolve standard linting and analysis issues.
# Preview changes
dart fix --dry-run
# Apply changes
dart fix --apply
3. Resolve remaining errors manually Review the remaining analyzer output and apply conditional logic based on the error type:
?.) or provide a fallback (??).late.<int>[] instead of []).covariant keyword to the parameter if tightening the type is intentionally required by the domain logic.4. Verify fixes (Feedback Loop) Run the validator. Review errors. Fix.
dart analyze .
dart test
dart analyze reports errors: Return to Step 3.dart test fails with a TypeError: You have introduced an invalid explicit cast (as T) or accessed an uninitialized late variable. Locate the runtime failure and correct the type hierarchy or initialization order.Input (Fails Static Analysis):
void printInts(List<int> a) => print(a);
void main() {
final list = []; // Inferred as List<dynamic>
list.add(1);
list.add(2);
printInts(list); // Error: List<dynamic> can't be assigned to List<int>
}
Output (Passes Static Analysis):
void printInts(List<int> a) => print(a);
void main() {
final list = <int>[]; // Explicitly typed
list.add(1);
list.add(2);
printInts(list);
}
Input (Fails Static Analysis):
class Animal {
void chase(Animal a) {}
}
class Cat extends Animal {
@override
void chase(Mouse a) {} // Error: Tightening parameter type
}
Output (Passes Static Analysis):
class Animal {
void chase(Animal a) {}
}
class Cat extends Animal {
@override
void chase(covariant Mouse a) {} // Explicitly marked covariant
}
lateInput (Fails Static Analysis):
class Thermometer {
String temperature; // Error: Non-nullable instance field must be initialized
void read() {
temperature = '20C';
}
}
Output (Passes Static Analysis):
class Thermometer {
late String temperature; // Defers initialization check to runtime
void read() {
temperature = '20C';
}
}
npx claudepluginhub flutter/agent-plugins --plugin dart-flutterRuns `dart analyze` to find warnings/errors and applies `dart fix --apply` to resolve mechanical lint issues. Use during development and before commits.
Reviews Flutter/Dart code against a checklist covering widget best practices, state management patterns, Dart idioms, performance, accessibility, security, and clean architecture.
Systematically investigates Flutter bugs using logging, DevTools, debug widgets, and breakpoints. Use for widget errors, state issues, test failures, etc.