flutter-context-watch-instead-of-top-builder
Installation
SKILL.md
Flutter context.watch Instead of Top Builder
Goal
Replace a top-level BlocBuilder<Cubit, State> with context.watch<Cubit>() in build, while keeping the same UI behavior.
Workflow
- Identify a root
BlocBuilderwrapping most of the screen. - Inside
build, read the cubit once:final cubit = context.watch<MyCubit>();final state = cubit.state;
- Remove the outer
BlocBuilderand return the wrapped widget directly. - Keep write actions as
context.read<MyCubit>()in handlers (onTap, submit, etc.). - If
presentationstream listeners exist (foruseOnStreamChange), usecubit.presentationso there is a single watched cubit reference. - Validate no behavior changes: loading, list size, buttons, and side effects should match previous logic.