Toggle Dark/Light/Auto modeToggle Dark/Light/Auto modeToggle Dark/Light/Auto modeBack to homepage
State notifier
• Section: Dart
Writing a State Notifier
The issue is that StateNotifier only notifies listeners when you reassign the state property.
When you mutate the existing state object (which is what’s happening with state.add(), state.nextReady(), etc.), the StateNotifier doesn’t detect the change and doesn’t notify listeners.
This pattern of reassigning state = state works because
StateNotifier uses a setter that compares the identity of the state object
Even though you’re mutating the internal collections (LRUFixedMap), the state object reference remains the same
By reassigning state = state, you explicitly tell StateNotifier that the state has changed, triggering all listeners
Key Takeaway
With StateNotifier (and similar state management patterns like ChangeNotifier), you need to explicitly trigger notifications.
Unlike some reactive frameworks that detect mutations automatically, StateNotifier relies on you to signal when the state has changed by reassigning the state property.