Flutter Performance
ASecurityThe issue is that the cart count change is coupled to the whole page state, so the expensive product grid rebuilds too. Fix it by isolating the header update from the grid: - Do not call `setState()` at the page/root level for cart count changes. - Put the cart badge/header in its own `BlocBuilder` with `buildWhen`, or use `context.select()` / `BlocSelector` so only the count widget rebuilds. - Keep the product grid as a separate widget with stable inputs; make static children `const` where p...
- 584 stars
- 0 votes
- 0 copies
- 1 view
- Added September 5, 2026
Security analysis
100/100Pro scans all 12 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill flutter-performance --agent claude-codeAre you the author of Flutter Performance?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-flutter-performance-72aa9936)The issue is that the cart count change is coupled to the whole page state, so the expensive product grid rebuilds too.
Fix it by isolating the header update from the grid:
- Do not call `setState()` at the page/root level for cart count changes.
- Put the cart badge/header in its own `BlocBuilder` with `buildWhen`, or use `context.select()` / `BlocSelector` so only the count widget rebuilds.
- Keep the product grid as a separate widget with stable inputs; make static children `const` where possible.
- If the grid is visually heavy, wrap it in `RepaintBoundary` so header changes do not trigger unnecessary repaints.
- Make sure any sorting/filtering work is outside `build()`.
Example:
```dart
class ShopPage extends StatelessWidget {
const ShopPage({super.key});
@override
Widget build(BuildContext context) {
return Column(
children: const [
_CartHeader(),
Expanded(child: RepaintBoundary(child: ProductGrid())),
],
);
}
}
class _CartHeader extends StatelessWidget {
const _CartHeader();
@override
Widget build(BuildContext context) {
final itemCount = context.select((CartBloc bloc) => bloc.state.itemCount);
return HeaderCartBadge(count: itemCount);
}
}
```
If using `BlocBuilder`, make it granular:
```dart
BlocBuilder<CartBloc, CartState>(
buildWhen: (prev, next) => prev.itemCount != next.itemCount,
builder: (context, state) => HeaderCartBadge(count: state.itemCount),
)
```
Main takeaway: rebuild only the cart-count widget, not the whole screen or product grid.
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- trigger-1.md
- trigger-2.md
- trigger-3.md
- trigger-4.md
- trigger-5.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.