custom-plugin-flutter-skill-performance
1600+ lines of performance optimization mastery - profiling, rendering, memory, network, battery, APK size with production-ready code examples.
What this skill does
# custom-plugin-flutter: Performance Optimization Skill
## Quick Start - Top 10 Optimizations
```dart
// 1. Use const constructors
const SizedBox(height: 16);
// 2. Extract widgets for rebuild optimization
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
children: [
const Title(), // Const - won't rebuild
BuildCounter(), // Rebuilds only when needed
],
);
}
}
// 3. Use ListView.builder
ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) => ItemTile(item: items[index]),
)
// 4. Cache network images
CachedNetworkImage(imageUrl: 'https://example.com/image.png')
// 5. Use RepaintBoundary for expensive widgets
RepaintBoundary(child: ExpensiveChart())
// 6. Profile regularly
// - Open DevTools Performance tab
// - Record timeline
// - Check frame rate and rebuild counts
// 7. Use const everywhere
const AppBar(title: Text('Title'))
// 8. Profile memory
// - Open DevTools Memory tab
// - Take heap snapshots
// - Look for memory leaks
// 9. Use SingleChildScrollView wisely
SingleChildScrollView(
child: Column(children: [...]),
)
// 10. Optimize images
Image.asset(
'assets/image.png',
cacheHeight: 500,
cacheWidth: 500,
)
```
## 1. Rendering Performance
**Frame Analysis:**
```dart
// Monitor frame rate with DevTools
// Target: 60 FPS (16.67ms per frame)
// Warning: 30-60 FPS (16-33ms)
// Danger: <30 FPS (>33ms)
class PerformanceMonitor {
void measureFrame() {
final start = DateTime.now();
// Do work
final duration = DateTime.now().difference(start);
print('Frame took ${duration.inMilliseconds}ms');
}
}
```
**Preventing Jank:**
```dart
// Bad: Expensive computation on main thread
class BadWidget extends StatefulWidget {
@override
State<BadWidget> createState() => _BadWidgetState();
}
class _BadWidgetState extends State<BadWidget> {
@override
Widget build(BuildContext context) {
final expensive = expensiveComputation(); // Blocks UI!
return Text('Result: $expensive');
}
}
// Good: Use Isolate or async
class GoodWidget extends StatefulWidget {
@override
State<GoodWidget> createState() => _GoodWidgetState();
}
class _GoodWidgetState extends State<GoodWidget> {
late Future<dynamic> _computation;
@override
void initState() {
super.initState();
_computation = compute(expensiveComputation, null);
}
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: _computation,
builder: (context, snapshot) {
if (snapshot.hasData) {
return Text('Result: ${snapshot.data}');
}
return CircularProgressIndicator();
},
);
}
}
```
## 2. Memory Optimization
```dart
// Memory profiling with DevTools
// Target: <100MB for typical app
// Peak: <150MB during heavy operations
class MemoryOptimized {
// Bad: Keep large objects in memory
List<LargeObject> _cache = [];
// Good: Limited cache size
final _cache = LimitedQueue<LargeObject>(maxSize: 50);
void dispose() {
_cache.clear();
}
}
class LimitedQueue<T> {
final int maxSize;
final _queue = <T>[];
LimitedQueue({required this.maxSize});
void add(T item) {
_queue.add(item);
if (_queue.length > maxSize) {
_queue.removeAt(0);
}
}
void clear() => _queue.clear();
}
```
## 3. APK/IPA Size Reduction
**Build with size analysis:**
```bash
# Android - analyze size
flutter build apk --release --analyze-size
# iOS - check build size
ls -lh build/ios/Release-iphoneos/app.ipa
```
**Reduce size:**
```gradle
// android/app/build.gradle
android {
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
// Split APKs by ABI
flutter build apk --split-per-abi
```
## 4. Network Optimization
```dart
// Connection pooling with Dio
final dio = Dio(BaseOptions(
connectTimeout: Duration(seconds: 10),
));
// Cache responses
dio.interceptors.add(
CacheInterceptor(
options: CacheOptions(
store: MemoryCacheStore(),
policy: CachePolicy.request,
maxStale: Duration(days: 7),
),
),
);
// Batch requests
Future<(UserList, PostList)> fetchUserAndPosts(String userId) async {
final futures = await Future.wait([
dio.get('/users/$userId'),
dio.get('/posts?userId=$userId'),
]);
return (
UserList.fromJson(futures[0].data),
PostList.fromJson(futures[1].data),
);
}
```
---
**Build lightning-fast, efficient Flutter apps.**
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.