...

/

The provider Package

The provider Package

Understand how to use the provider package to manage the state within your Flutter application.

Introduction to the provider package

The provider package uses InheritedWidget under the hood. It offers a simplified, low-boilerplate approach to state management. The provider package makes it easy to separate the UI and logic of an application.

Defining provider at the top of a widget tree makes the app state accessible to all child widgets.

Press + to interact
The provider added to the child in the widget tree
The provider added to the child in the widget tree

The provider state can then be accessed down the widget tree

In this tutorial, we’ll update the state of the app below using provider:

Bud1�lsdsclboolmodelsdsclboolpresentationdsclbool @� @� @� @E�DSDB ` @� @� @
State management with the provider package—starter code

Using the provider package

We first need to install the provider package. Locate # TODO-1: Add provider package dependency (line 17) in the pubspec.yaml file and install the package, as shown below:

Press + to interact
provider: ^6.0.2

The provider package exposes different objects that our application can use in state management. In this lesson, we’ll work with the ChangeNotifierProvider object. We’ll need to understand the following concepts:

...