State ManagementIntermediate30 XP3 min read
What is reactive programming and how does it apply to Flutter?
TL;DR: Reactive programming models data as streams of values over time. Flutter's ValueNotifier, Stream, and ChangeNotifier are all reactive primitives — UI subscribes and reacts to changes automatically.
Full Answer
Reactive programming inverts control: instead of polling for changes, you subscribe to change streams and the system pushes updates to you.
- ▸ValueNotifier<T> — simplest reactive primitive; addListener/notifyListeners
- ▸ValueListenableBuilder — rebuilds when ValueNotifier changes
- ▸Stream<T> / StreamController — async push-based data sequence
- ▸StreamBuilder — rebuilds on each stream event
- ▸ChangeNotifier — multi-field reactive model
- ▸RxDart — extends Dart streams with BehaviorSubject, ReplaySubject, operators
🎯
ValueNotifier + ValueListenableBuilder is a lightweight alternative to StatefulWidget for single-value state. It's built into Flutter with zero dependencies.
Code Examples
dartValueNotifier for simple reactive state
Output
Counter updates reactively; 'Static label' never rebuilds since it's the non-reactive child
Common Mistakes
- ✗Forgetting to call counter.dispose() — ValueNotifier is a ChangeNotifier; dispose prevents leaks
- ✗Not using the child parameter in ValueListenableBuilder — expensive static subtrees rebuild unnecessarily
Interview Tip
💡
ValueNotifier is often overlooked. Mentioning it as a zero-dependency option for simple reactive state shows breadth of Flutter knowledge.
#reactive#streams#RxDart#ValueNotifier#ChangeNotifier