Member-only story
Observable Models
Look, one of the power Google moves in flutter state management is to create observers that could be used in MVC-Models and MVVM-BaseModels to make state management somewhat app architecture agnostic. But, there are some tricks to make it easy to use rather than hard.
In this example, I will use the Change Notifier edition of model observers. And, I will also cover mocking this change notifier and fully unit testing it.
Notifiers As Model Observers
Notifiers are just specialized observers using the observer pattern, which are in fact ways to add a listener and observer state changes of the listener. And all listeners are call-backs that do not return anything.
Listeners as just a list of VoidCallbacks with methods to add and remover listeners:
from flutter source code, the change_notifier dart file
And Change Notifiers are mutable, which means the underlying model cannot be expected to be a value type model. For example, in the flutter framework, the scroll controller uses a change notifier for the scroll…