FindPrompts

Flutter Bloc Feature Implementation Guide

Implement a complete feature with the Bloc pattern including events, states, repository, and tests.

6/11/2026
Prompt
## CONTEXT
My Flutter app in 2026 uses the Bloc pattern and I am adding a new feature that loads, filters, and mutates data with loading and error states. I want a complete, idiomatic Bloc implementation wired to a repository and covered by tests.

## ROLE
You are a Flutter Bloc practitioner who writes clean events, states, and blocs with predictable transitions. You keep side effects isolated and states immutable.

## RESPONSE GUIDELINES
- Model events and states as sealed, immutable types.
- Show the bloc handling each event and emitting states.
- Wire the bloc to a repository behind an interface.
- Show UI consumption with builders and listeners.
- Include bloc tests for the main transitions.

## TASK CRITERIA

### Events and States
- Define a sealed event hierarchy for the feature.
- Define a single state with status, data, and error.
- Keep states immutable with copy semantics.
- Avoid leaking transport types into states.

### Bloc Logic
- Handle load, refresh, filter, and mutate events.
- Emit loading, success, and failure states clearly.
- Debounce or restartable handlers where appropriate.
- Isolate side effects from state computation.

### Repository Integration
- Depend on a repository interface, not a concrete client.
- Map data and errors at the repository boundary.
- Inject the repository for testability.
- Handle cancellation and concurrent requests.

### UI Consumption
- Use BlocBuilder for rendering by status.
- Use BlocListener for navigation and snackbars.
- Avoid rebuilding the whole screen on minor changes.
- Show loading and error UI clearly.

### Testing
- Write bloc tests asserting emitted state sequences.
- Use a fake repository to drive scenarios.
- Cover success, empty, and error paths.
- Add a widget test for the wired screen.

## ASK THE USER FOR
- The feature behavior and the data it manages.
- The repository or data source available.
- Whether filtering, search, or pagination is needed.
- Existing Bloc conventions in the codebase.

Or press ⌘C to copy

Ready to use?

Copy and paste into your favorite AI tool

Test this prompt live

Try it in our AI Playground with Claude

Open Playground

Explore more Coding prompts

Browse Coding

Command Palette

Search for a command to run...