Flutter State Review
When to use this skill
- •When reviewing Flux or UI code.
- •When fixing bugs related to UI not updating.
- •When refactoring "Spaghetti code" in Widgets.
How to use it
- •Ban Logic in UI:
- •Ensure
build()methods only containBlocBuilder,BlocListener, or simple rendering logic. - •VIOLATION: Calling
FirebaseFirestore.instance...directly inside a Widget. - •VIOLATION: Calling
setStatefor business logic state.
- •Ensure
- •Review Bloc Dependencies:
- •Blocs should depend on Repositories, not data sources directly.
- •Repositories should handle the data fetching/stream subscription.
- •Stream Safety:
- •Verify that data streams are properly managed (listened to in the Data layer, yielded as states in the Bloc).
- •Ensure streams are closed/cancelled when not needed (though Bloc usually handles this for subscriptions it manages).
- •One-Way Data Flow:
- •Action (UI) -> Event (Bloc) -> New State (Bloc) -> Rebuild (UI).
- •Ensure no side-effects bypass this flow.