Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/flutter/agent-plugins --skill dart-fix-runtime-errors- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads dart-fix-runtime-errors automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
Security audits
Independent scans of the skill's instructions and bundled files.
SKILL.md
The instructions your agent reads when the skill is triggered.
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.
Null Safety
Eliminate static errors related to null safety by correctly managing variable initialization and nullability.
- Modifiers: Apply
?for nullable types,!for null assertions, andrequiredfor named parameters that cannot be null. - Late Initialization: Use the
latekeyword 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. - Wildcards: Use the
_wildcard variable (Dart 3.7+) for non-binding local variables or parameters to avoid unused variable warnings.
Error Handling
Distinguish between recoverable exceptions and unrecoverable errors.
- Catching: Catch
Exceptionsubtypes for recoverable failures. - Errors: Never explicitly catch
Erroror its subtypes (e.g.,TypeError,ArgumentError). Errors indicate programming bugs that must be fixed, not caught. Enforce this by enabling theavoid_catching_errorslinter rule. - Rethrowing: Use
rethrowinside acatchblock to propagate an exception while preserving its original stack trace.
Workflows
Workflow: Static Analysis Resolution
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.
- 2. Apply automated fixes.
- 3. Resolve remaining errors manually.
- 4. Verify fixes (Feedback Loop).
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:
- If the error is a Null Safety issue (e.g., "Property cannot be accessed on a nullable receiver"):
- Verify if the variable can logically be null.
- If yes, use optional chaining (
?.) or provide a fallback (??). - If no, and initialization is guaranteed elsewhere, mark the declaration with
late.
- If the error is a Type Mismatch (e.g., "The argument type 'List<dynamic>' can't be assigned..."):
- Trace the variable's initialization.
- Add explicit generic type annotations to the instantiation (e.g.,
<int>[]instead of[]).
- If the error is an Invalid Override (e.g., "The parameter type doesn't match the overridden method"):
- Widen the parameter type to match the superclass, OR
- Add the
covariantkeyword 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
- If
dart analyzereports errors: Return to Step 3. - If
dart testfails with aTypeError: You have introduced an invalid explicit cast (as T) or accessed an uninitializedlatevariable. Locate the runtime failure and correct the type hierarchy or initialization order.
Examples
Example: Fixing Dynamic List Assignments
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);
}
Example: Fixing Method Overrides (Contravariance)
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
}
Example: Fixing Null Safety with late
Input (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';
}
}
FAQ
What does the dart-fix-runtime-errors skill do?
Uses getruntimeerrors and lsp to fetch an active stack trace, locate the failing line, apply a fix, and verify resolution via hotreload.
How do I install dart-fix-runtime-errors?
Run npx skills add https://github.com/flutter/agent-plugins --skill dart-fix-runtime-errors in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/dart-fix-runtime-errors/ (personal) or .claude/skills/dart-fix-runtime-errors/ (project).
Which AI agents can use dart-fix-runtime-errors?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is dart-fix-runtime-errors safe to install?
Security partners have reviewed it: Gen Agent Trust Hub passed; Socket passed; Snyk passed. As with any skill, read the SKILL.md and bundled scripts before installing.
Who maintains dart-fix-runtime-errors?
It is published by flutter in flutter/agent-plugins. It has 14,668 recorded installs.
More from flutter/agent-plugins
flutter-apply-architecture-best-practices
flutter/agent-plugins
Architects a Flutter application using the recommended layered approach (UI, Logic, Data). Use when structuring a new project or refactoring for scalability.
flutter-build-responsive-layout
flutter/agent-plugins
Use LayoutBuilder, MediaQuery, or Expanded/Flexible to create a layout that adapts to different screen sizes. Use when you need the UI to look good on both mobile and tablet/desktop form factors.
flutter-fix-layout-issues
flutter/agent-plugins
Fixes Flutter layout errors (overflows, unbounded constraints) using Dart and Flutter MCP tools. Use when addressing "RenderFlex overflowed", "Vertical viewport was given unbounded height", or similar layout issues.
flutter-add-widget-test
flutter/agent-plugins
Implement a component-level test using WidgetTester to verify UI rendering and user interactions (tapping, scrolling, entering text). Use when validating that a specific widget displays correct data and responds to events as expected.
flutter-add-integration-test
flutter/agent-plugins
Configures Flutter Driver for app interaction and converts MCP actions into permanent integration tests. Use when adding integration testing to a project, exploring UI components via MCP, or automating user flows with the integrationtest package.
flutter-setup-declarative-routing
flutter/agent-plugins
Configure MaterialApp.router using a package like gorouter for advanced URL-based navigation. Use when developing web applications or mobile apps that require specific deep linking and browser history support.
Popular mobile skills
design-mobile-apps
designed-by-ai/skills
Design mobile app screens with Sleek, edit Sleek projects, and implement their designs in React Native or HTML.
ios-design
uizze.sh
Design and review iOS UI/UX for iPhone apps in SwiftUI, UIKit, or React Native. Use for mobile app design, screen redesigns, navigation flows, typography, forms, keyboard and safe-area layout, and accessibility checks. Apply Apple Human Interface Guidelines and consult real product references through the optional Uizze connection.
vercel-react-native-skills
vercel-labs/agent-skills
React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.
animate-expo
emilkowalski/skills
Build animations in React Native and Expo, making the decisions in the order that determines whether they feel right — should it animate, which thread it runs on, which properties, spring or timing, how the gesture hands off, how it degrades. Writes the implementation with Reanimated, Gesture Handler, Expo Router and expo-haptics. Use when animating anything in an Expo app, adding gestures, sheets, screen transitions, press feedback or haptics, or fixing motion that stutters on device. For web animation use animate.
xcode-project-setup
firebase/agent-skills
Safely modifies Xcode projects (.pbxproj) to add Swift Packages and link files. Use this skill whenever an iOS project needs dependencies installed (e.g. Firebase, Alamofire).
firebase-remote-config-basics
firebase/agent-skills
Manages Firebase Remote Config templates, feature flags, loading strategies, and SDKs (Android, iOS). Use when downloading/deploying remoteconfig JSON templates, managing version history/feature flags, setting in-app defaults, fetchAndActivate(), real-time listeners, or SDK setup. Don't use for Firebase Hosting, Auth, Firestore, Data Connect, Crashlytics, or App Hosting.
