What you'll learn
Compare Provider, Riverpod, BLoC, reducers, and state machines by concrete pressures while keeping domain architecture independent. The lesson turns the APIs into a repeatable engineering workflow instead of a collection of isolated snippets.
By the end of this lesson, you'll be able to:
- Apply Provider tradeoffs in a production-shaped Flutter feature
- Apply Riverpod concepts in a production-shaped Flutter feature
- Apply BLoC in a production-shaped Flutter feature
- Apply Reducers in a production-shaped Flutter feature
Core mental model
Connect each API to the decision it supports. Flutter code stays maintainable when state, ownership, lifecycle, and platform boundaries are explicit.
| Concept | What it means | Decision rule |
|---|---|---|
| Reducer | A pure function maps current state and an event to next state | Use when transitions must be explicit and exhaustively tested |
| BLoC | Events are transformed into states through a dedicated component | Use when event workflows and team conventions justify the structure |
| Provider scope | A dependency or state owner is attached to a subtree | Place it at the narrowest lifecycle shared by all consumers |
Professional workflow
Work in small vertical slices and keep behavior observable from the first iteration.
- Define the explicit feature state machine boundary: user goal, inputs, visible states, ownership, and expected failures.
- Build the smallest working vertical slice with typed data and explicit dependencies.
- Represent loading, empty, success, and failure behavior where the feature can encounter them.
- Verify logic away from the UI, then exercise the rendered behavior at its public boundary.
- Inspect lifecycle, accessibility, performance, security, and platform behavior before widening the feature.
- Refactor only after behavior is protected by repeatable evidence.
Protect the frame
Guided Flutter lab
Build a focused explicit feature state machine slice
This compact example keeps the important ownership and data-flow decisions visible so the behavior is easy to extend and test.
sealed class ProgressEvent { const ProgressEvent(); }
class LessonCompleted extends ProgressEvent { const LessonCompleted(this.id); final String id; }
class ProgressReset extends ProgressEvent { const ProgressReset(); }
Set<String> reduceProgress(Set<String> state, ProgressEvent event) => switch (event) {
LessonCompleted(id: final id) => {...state, id},
ProgressReset() => <String>{},
};
void main() {
assert(reduceProgress({}, const LessonCompleted('dart-1')).contains('dart-1'));
}Production practice
Contract
Define the explicit feature state machine inputs, outputs, owner, lifecycle, visible states, and platform assumptions before selecting APIs or packages.
Verification
Protect pure rules with unit tests and the rendered public contract with widget or integration evidence; include one unavailable or failure case.
Operations
Keep dependencies replaceable, log actionable context without user secrets, and measure user-visible behavior before optimizing.
Common failure mode
Independent workshop
Extend the guided lab into a review-ready explicit feature state machine feature that fits the running course portfolio app.
Your finished workshop must include:
- Provider tradeoffs
- Riverpod concepts
- BLoC
- Reducers
- State machines
- Automated verification and a short design note
Definition of done
Recap & quick check
Key takeaways
- Reducer: Use when transitions must be explicit and exhaustively tested
- BLoC: Use when event workflows and team conventions justify the structure
- Provider scope: Place it at the narrowest lifecycle shared by all consumers
Quick check
1. Which rule best applies to Reducer?
2. Which rule best applies to BLoC?
3. Which rule best applies to Provider scope?
Next: Complete Flutter Testing Strategy