bloc-state-management_skill

This skill helps you implement predictable Flutter BLoC state management with freezed and equatable, guiding events, states, and UI integration.
  • TypeScript

227

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill hoangnguyen0403/agent-skills-standard --skill bloc-state-management

  • SKILL.md1.7 KB

Overview

This skill codifies standards for predictable, testable Flutter state management using flutter_bloc, freezed, and equatable. It provides a clear workflow for designing events, states, and BLoC logic to keep UI layers thin and side effects isolated. The goal is robust, maintainable flows that are easy to test and reason about.

How this skill works

Start by modeling user interactions and outcomes as @freezed union types for Events and States. Implement a BLoC that maps Events to States using on<Event> handlers, async emit patterns, and transformers for concurrency. Connect the UI with BlocBuilder for rendering and BlocListener for navigation and other side effects, while ensuring errors become Failure states rather than thrown exceptions.

When to use it

  • When you need predictable, testable state flows across screens or features.
  • When UI must reflect asynchronous data sources such as APIs or streams.
  • When multiple UI components need to react to the same business logic.
  • When you want to keep navigation and one‑off effects out of build methods.
  • When you need easy unit and blocTest coverage for state transitions.

Best practices

  • Define all Events and States with @freezed to get exhaustive unions and pattern matching.
  • Emit errors as Failure states; avoid throwing inside on<Event> handlers.
  • Use await or emit.forEach for async work; avoid .then() chains that complicate tests.
  • Keep BlocBuilder pure (rendering only); place navigation and Snackbars in BlocListener.
  • Use transformer: restartable() (or debounce) for search/typeahead to manage concurrency.

Example use cases

  • A search screen using restartable transformer to handle rapid query changes and emit Loading/Data/Error states.
  • An authentication flow with Initial, Loading, Authenticated, and Unauthenticated states and tests covering all transitions.
  • A realtime feed implemented with emit.forEach(stream) to map incoming items to Data states while preserving testability.
  • A form submission flow where validation and API calls are handled in the BLoC and UI shows states via BlocBuilder and Snackbars via BlocListener.

FAQ

Emit states that represent outcomes and handle navigation or Snackbars in BlocListener rather than in BlocBuilder or the BLoC emitting direct navigator calls.

What testing approach is required?

Use blocTest to cover all state transitions, verify the initial state, and mock async dependencies so tests assert emitted states only.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
bloc-state-management skill by hoangnguyen0403/agent-skills-standard | VeilStrat