What is difference between valueNotifier,changeNotifier,stateNotifier?
-
Does this answer your question? [Implement ChangeNotifier vs StateNotifier](https://stackoverflow.com/questions/62946841/implement-changenotifier-vs-statenotifier) – Md. Yeasin Sheikh Apr 14 '22 at 11:33
2 Answers
ValueNotifier is a special type of class that extends Changenotifier, which can hold a single value and notifies the widgets which are listening to it whenever its holding value gets change.
ChangeNotifier is a class that provides change notification to its listeners. That means you can subscribe to a class that is extended or mixed in with ChangeNotifier and call its notifyListeners() method when there’s a change in that class. This call will notify the widgets that are subscribed to this class to rebuild.
On the other hand, StateNotifier is an immutable state management solution where the state can be directly changed within the notifier only.

- 186
- 6
There is an interesting difference between ValueNotifier and StateNotifier. The former uses ==
to assess whether update is needed, while later uses identical
check. This has positive performance implications in favor of the later as long as immutable types are used. See https://github.com/rrousselGit/state_notifier#why-are-listeners-called-when-the-new-state-is--to-the-previous-state
For built-in "value types" and enums they work just the same.
One may be tempted to use ValueNotifier for mutable objects, but this doesn't work well because sub-objects of that object can be changed via mutating methods, and this clearly does not trigger updates.
StateNotifier also has some additional options, such as modifying when the value is actually updated.
Therefore my current recommendation is:
- Use ChangeNotifier for mutable types.
- Use StateNotifier for immutable types.
- Ignore ValueNotifier.
StateNotifier is intended to be used with immutable objects, but there is no mechanism in the language to ensure this is the case. This compiles:
class Mutable {
Object? o;
}
class Mistake extends StateNotifier<Mutable> {
Mistake() : super(Mutable());
}

- 400
- 2
- 8