Skip to content
pubscout

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
$ flutter pub add state_notifier
Source repository

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.