Now it's time to make our application work. For the Riverpod magic to work, you need to wrap the entire ProviderScope application with a widget:Since _counterProvider is a global constant, we can access it from anywhere . You usually hear in programming that you shouldn't use global variables. One reason is that it's easy to get subtle errors if different parts of your code change a variable. However, this global variable is immutable, so there is no danger of changing it.
MyHomePage is currently a successor to StatelessWidget. Change the StatelessWidget to a ConsumerWidget to get a "ref" object. This object allows us to interact with providers, be it a widget or another provider. The ref object has a read method. Unlike watch, the read method gives you a reference to your state management class without tracking changes in state. The reason this is important is that the watch behind the CounterNotifier will cause the widget's build method to rerun when the state changes. If the widget, in this case FAB , does not visually change in any way, it is somehow useless to redraw it.
United States Latest News, United States Headlines
Similar News:You can also read news stories similar to this one that we have collected from other news sources.
Source: njdotcom - 🏆 282. / 63 Read more »
Source: SheKnows - 🏆 558. / 51 Read more »
Source: verge - 🏆 94. / 67 Read more »
Source: hackernoon - 🏆 532. / 51 Read more »
Source: hackernoon - 🏆 532. / 51 Read more »
Source: hackernoon - 🏆 532. / 51 Read more »