skills/dart/dart-optimization/SKILL.md
Optimize Dart code for performance, type safety, and runtime error prevention. Use when profiling hot paths, enforcing sound typing, handling null safety, or debugging type mismatches and runtime failures.
npx skillsauth add dhruvanbhalara/skills dart-optimizationInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Performance in Dart goes beyond UI rendering; it's about efficient execution, smart resource utilization, and sound error handling.
dynamic. Use explicit types or Object?. Statically typed code allows the compiler to perform far better optimizations.Set for average O(1) containment checks.List for ordered indexing.Iterable methods (map, where) for readability, but use for loops in performance-critical hot paths.final whenever possible. Use const constructors for widgets and data models to enable compile-time allocation and reduce runtime garbage collection pressure.switch expressions (Dart 3+) for exhaustive and efficient pattern matching.[] or {} instead of constructors like List() for brevity and minor performance gains.Enforce Dart's sound type system to prevent runtime invalid states.
covariant keyword.List<T>). Never assign a List<dynamic> to a typed list.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 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.Exception subtypes for recoverable failures.Error or its subtypes (e.g., TypeError, ArgumentError). Errors indicate programming bugs that must be fixed, not caught.rethrow inside a catch block to propagate an exception while preserving its original stack trace.package:benchmark_harness for scientific performance measurement of non-UI logic.development
Perform REST API networking operations (GET, POST, PUT, DELETE) using the lightweight and robust standard `http` package, including platform configurations and background parsing models.
development
Configure internationalization and localization support using Flutter's built-in l10n system, App Resource Bundle (ARB) files, and ICU formatting syntax.
development
Create model classes with fromJson/toJson using dart:convert and Dart 3 pattern matching. Use when manually mapping JSON to classes, parsing HTTP responses, or choosing between manual and code-generated serialization.
data-ai
Diagnose and fix Flutter layout constraint violations (RenderFlex overflow, unbounded height/width, ParentData misuse). Use when encountering layout exceptions, yellow-black overflow stripes, or red error screens.