The Consumer Widget: Application
Continue to learn about the consumer widget and how you can implement it in an actual application.
We'll cover the following...
How to notify listeners?
We need the ChangeNotifierProvider widget that provides an instance of a ChangeNotifier to its descendants. It comes from the provider package.
Now our task becomes much more manageable. Because we place ChangeNotifierProvider at the top of all widgets, any descendant widget can access the state from it directly.
We can now provide the CountingTheNumber model to any descendant widgets in our app through the ChangeNotifierProvider. We have already declared ChangeNotifierProvider at the top so we can start using it.
How can we access the changed data? How can we change the state through the consumer widget?
We’re closing towards the lesser-known facts of Provider package. As we have just seen, the ChangeNotifierProvider provides only the CountingTheNumber model class, which we have placed in our model folder.
Soon, we’ll ...