Loading...
Loading...
Enforces Flutter runtime performance — const subtrees, minimal rebuild scope via ref.watch(select), lazy ListView/GridView builders and slivers, sized image decode (cacheWidth/ResizeImage), heavy work off the UI isolate via compute/Isolate, surgical RepaintBoundary, dispose everything, and measurement in profile mode on a floor device. Use when optimizing UI, diagnosing jank or dropped frames, tuning long lists or images, reviewing rebuild/repaint scope, or when the task mentions const, select, ListView.builder, cacheWidth, compute, RepaintBoundary, AnimatedBuilder, DevTools, raster thread, or 60/120fps.
npx skill4agent add zakariaf/flutter-skills flutter-performanceconstconstprefer_const_constructorsref.watch(provider)provider.select((s) => s.field)ListView.builderGridView.builderListView(children: items.map(...).toList())build()jsonDecodeDateTimebuild()compute()IsolatecacheWidthcacheHeightResizeImageprecacheImageColoredBoxDecoratedBoxContainerSizedBoxFadeTransitionAnimatedOpacityOpacityClipPathsaveLayerRepaintBoundarychild:AnimatedBuilderValueListenableBuilderStreamBuilderbuilderchild:AnimationControllerTextEditingControllerdispose()ref.onDisposeautoDisposesaveLayer// Rebuilds only when the count changes, not on every OrderState mutation.
class OrderBadge extends ConsumerWidget {
const OrderBadge({super.key});
Widget build(BuildContext context, WidgetRef ref) {
final count = ref.watch(orderProvider.select((s) => s.items.length));
return Text('$count');
}
}.select==state-management-riverpodfamilyautoDispose// The card is built once; only the transform recomputes each tick.
AnimatedBuilder(
animation: _controller,
child: const ProductCard(),
builder: (_, child) =>
Transform.scale(scale: _controller.value, child: child),
);// Lazy — only visible rows are built.
ListView.builder(
itemCount: items.length,
itemBuilder: (context, i) => ItemTile(item: items[i]),
);
// Decode to the slot, not the source resolution.
Image.asset('assets/hero.png', cacheWidth: 240);// parseItems is a top-level or static function (isolate entry-point rules).
final items = await compute(parseItems, jsonString);CustomPainterpaint()shouldRepaintrepaint:ListenableAnimationControllersetStatecustom-canvas-and-gesturesPaintPathGradientpaint()flutter run --profile.selectconstbuild()OpacitysaveLayerRepaintBoundarysetState()ref.watch(provider).selectListView(children: [...].toList())jsonDecodeDateTimebuild()OpacitysaveLayerFadeTransitioncomputeRepaintBoundaryAnimatedBuilderStreamBuilderchild:PaintPathpaint()constprefer_const_constructors.select.builderbuild()computeIsolatecacheWidthResizeImageRepaintBoundarychild:CustomPainterpaint()shouldRepaintautoDisposestate-management-riverpod.selectfamilyautoDispose.selectwidget-compositionconst_buildXcustom-canvas-and-gesturespaint()shouldRepaintrepaint:Listenabletesting-strategy