SimpleNotifier
Just create a class that extends of SimpleNotifier
SimpleProvider#
Now you need to create a provider as a global variable using the SimpleProvider class.
Now you can use the Consumer widget to read your CounterController.
By default the counterProvider variable doesn't create one instance of CounterController until it is need it. In this case the Consumer
widget call to the read method of our counterProvider and check if the CounterController was created and return the CounterController that was created before or create a new CounterController.
The onDispose method in our CounterController will be called when the route who created the CounterController is popped.
If you don't want to call to the onDispose method when the route who created the CounterController is popped you could use.
WARNING
When you disable the autoDispose of your provider you need to handle it manually. For example
Listen the changes in your Controller#
You could use the ProviderListener Widget to listen the changes in our CounterController
Or you can listen the changes in your SimpleProvider as a StreamSubscription
watch method with WatchFilter#
If you have multiples Consumer widgets in your Views and you only want rebuild certain Consumer you can use the WatchFilter
note
When you use the WatchFilter class you need to define the generic types in the watch method.
The second generic type in the next code in our WatchFilter is a List beacuse we are using a list of strings (ids) to listen the changes.
If you don't want to use ids to rebuild your Consumer you can use the select param in the WatchFilter instance.
The next code rebuilds the first Consumer only when the counter is highest than 5.
note
The second generic type in the next code in our WatchFilter is a bool beacuse we are using a boolean condition to listen the changes.
ConsumerWidget#
Also you can extend from ConsumerWidget to create a widget and listen the changes in your notifier
NOTE
The watch method in a Consumer or a ConsumerWidget can be used to listen multiples providers.