Understanding State Management Using Providers in Flutter

Meysam Mahfouzi
8 min readFeb 2, 2021

Everything around us has a state. For example, what are the states of a thermometer?

  • The color of the metal plate (white)
  • The color of the liquid (red)
  • The height of the liquid in the tube (e.g. 10 centimeters)
Photo by Jarosław Kwoczała on Unsplash

And what are the states of weather?

  • Temperature (40˚C)
  • Speed of the wind
  • Sunny or cloudy
  • Rainy or snowy

Now what’s State Management? State management is updating the state of one thing, based on the state of another thing.

This state management happens automatically in nature. Whenever the sun rises, the state of birds changes to “singing”. Whenever it rains, the state of soil changes to “Wet” and its color becomes darker. Whenever the temperature increases, the height of the liquid in thermometer increases as well. Every change in the state of things is managed automatically.

But in Flutter, we have to manage the state changes ourselves. Welcome to the United States of Flutter!

Using setState

The simplest way to manage state changes in Flutter is by calling the setState() method. That works fine if everything gets changed and…

--

--