Step-by-Step Guide for Provider

Summarize how you can use the `Provider` package for state management in a working Flutter application.

Adding the Provider dependency

First, we will add the dependency on the Provider to our pubspec.yaml file.

Press + to interact
...
dependencies:
flutter:
sdk: flutter
provider: ^5.0.0

At the time of writing this course, the Provider package is 5 and above. We should always check the latest version.

Mechanisms behind provider

The app state is something that we need to modify from many different places, and to do that, we have to pass around many callbacks. It will be suicidal to replace several widgets again and again for a complex widget tree.

To understand this mechanism, we need to find a solution that will not disturb the widget tree as a whole, yet the app state will modify a few widgets deep down the tree. Suppose we need to change one widget that has a hundred widgets on top of it.

Without disturbing the top hundred widgets, we can successfully handle the app state using Provider.

The mechanism

Flutter has built-in mechanisms for widgets to provide data and services to their distant descendants. It means not just the immediate ...

Get hands-on with 1400+ tech skills courses.