state_notifier
1.0.0, released 3 years ago by dash-overflow.net
ValueNotifier outside Flutter for managing state in an immutable manner.
WASM-ready
What it does
Provides a StateNotifier class to control application state outside Flutter with immutable objects. It supports change notifications based on object identity and integrates with Provider or Riverpod.
AI-written summary of version 1.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want a simple way to manage immutable state with Provider or Riverpod.
- You need to centralize business logic inside notifier classes.
Skip it when
- You want a complex out-of-the-box architecture with events and states like BLoC.
- You prefer mutable state notification classes like ChangeNotifier.
Strengths
- Enforces immutable state updates via centralized methods.
- Supports custom notification filtering via updateShouldNotify.
- Provides LocatorMixin for easy integration with dependency injection.
Weaknesses
- Relies on object identity (identical) by default, requiring custom updateShouldNotify overrides for deep equality comparisons.
- Updating state outside the notifier is considered an anti-pattern.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 1
class CityNotifier extends StateNotifier<List<City>> {
CityNotifier() : super(const <City>[]);
void addCity(City newCity) {
state = [...state, newCity];
}
}Works with
Packages commonly used together with state_notifier: ones it builds on, ones built on it, and its own family.
- riverpodBuilt on state_notifierA reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze.
- flutter_riverpodBuilt on state_notifierA reactive caching and data-binding framework for Flutter.
- hooks_riverpodBuilt on state_notifierA reactive caching, data-binding, and state management framework with flutter_hooks integration.
- segment_analyticsBuilt on state_notifierAdd Segment analytics to your Flutter app to track events, user screens, and identities.
- flutter_state_notifierBuilt on state_notifierFlutter bindings for state_notifier, providing StateNotifierProvider and StateNotifierBuilder.
- stream_videoBuilt on state_notifierOfficial low-level client for Stream Video, supporting calls, audio rooms, and live streaming.
- safe_change_notifierBuilt on state_notifierA drop-in replacement for Flutter's ChangeNotifier where notifyListeners() is a safe no-op after disposal.
- state_notifier_testBuilt on state_notifierA testing utility library for StateNotifier and Riverpod