Watchers are the fundamental part for interacting with Flutter when a part of your state changes.
If you just want to watch the state in a widget you can use the WatcherBuilder widget:
If you prefer to have dedicated stateless or stateful widgets with a built-in support of stores, you can extend from WatcherStatelessWidget or WatcherStatefulWidget:
For the WatcherStatefulWidget, the store is a property of the state:
If you want to update the value of a state, you need to do it in a Watcher, but not during the build phase:
Sometimes we don’t want to rebuild the UI but we want to execute some code when a state changes.
In this case we can use the WatcherEffect widget:
We will see how to separate the business logic from the UI in the next chapter.