dart-optimization
Optimization & Debugging
Performance in Dart goes beyond UI rendering; it's about efficient execution, smart resource utilization, and sound error handling.
Dart Performance Patterns
- Standardize Types: Avoid
dynamic. Use explicit types orObject?. Statically typed code allows the compiler to perform far better optimizations. - Efficient Collections:
- Use
Setfor average O(1) containment checks. - Use
Listfor ordered indexing. - Prefer
Iterablemethods (map,where) for readability, but useforloops in performance-critical hot paths.
- Use
- Inlining: Small getters and trivial functions are often inlined by the VM/AOT, but keeping them simple ensures this optimization happens.
Compile-Time Optimizations
- Final & Const: Declare variables as
finalwhenever possible. Useconstconstructors for widgets and data models to enable compile-time allocation and reduce runtime garbage collection pressure. - Ternary vs If-Else: In Dart, they are generally equivalent, but prioritize readability. Use
switchexpressions (Dart 3+) for exhaustive and efficient pattern matching.
Hot Paths & Loops
- Minimize Work in Loops: Extract calculations and object creations outside of loops.
- Collection Literals: Use literal syntax
[]or{}instead of constructors likeList()for brevity and minor performance gains.
More from dhruvanbhalara/skills
flutter-ui
Build performant, accessible UIs with strict design tokens and reusable widget patterns. Use when implementing layouts, responsive breakpoints, theming, widget extraction, or fixing common rendering issues like overflow errors.
178flutter-firebase
Integrate Firebase services including Authentication, Firestore, Cloud Messaging, Crashlytics, and Analytics. Use when adding backend capabilities, push notifications, crash reporting, or remote configuration to a Flutter app.
146flutter-dio
Implement HTTP networking with Dio including interceptors, retry logic, and response caching. Use when building API clients, configuring authentication headers, or handling network errors gracefully.
143flutter-security
Enforce architect-level security standards including AES-256-GCM encryption, secure storage, biometric gates, and memory safety. Use when handling sensitive data, credentials, clipboard content, or API communication security.
140flutter-architecture
Enforce Clean Architecture with BLoC pattern for Flutter applications. Use when scaffolding features, structuring data/domain/presentation layers, defining data models, or integrating native platform channels.
138flutter-debugging
Debug and profile Flutter applications using DevTools, structured logging, and memory analysis. Use when diagnosing layout issues, tracking performance bottlenecks, or setting up centralized error reporting with Crashlytics.
133