What is unidirectional data flow and why is it important in Flutter?
TL;DR: Unidirectional data flow means data moves in one direction: UI dispatches actions → state management processes them → new state flows back to UI. This makes state predictable and debuggable.
Full Answer
In a unidirectional flow: 1) User interacts with UI. 2) UI dispatches an Action/Event. 3) Reducer/BLoC produces a new State. 4) UI rebuilds from the new State.
This contrasts with two-way binding (common in Angular) where UI can directly mutate model data. With one-way flow, there's only one place state changes — making bugs easier to trace.
BLoC enforces unidirectional flow strictly. In Provider, it's possible to mutate the model from anywhere — discipline is required to maintain the pattern.
Code Examples
Flow: tap → SearchQueryChanged event → SearchLoading state → SearchSuccess state → ResultsList renders
Common Mistakes
- ✗Calling BLoC methods directly from deep UI widgets (bypassing the event system)
- ✗Updating state from multiple places without going through the BLoC — breaks traceability
Interview Tip
Connect unidirectional flow to testability — with UDF, you can replay any sequence of events and get deterministic state output.