The Different States in Flutter

initState? setState? What Are Those?

Beyond Boundaries
Beyond the Dev Life

--

If you’ve read my blog on how to get started with Flutter 2.0, you’ll know that Flutter supports stateless and stateful widgets. When we talk about states in Flutter, stateful widgets are of special interest.

Why?

Because they change their state during the lifespan of the app. In this blog, we want to discuss what a state is and what kind of states there are.

Image by author. Shot with Sony Alpha 58, 18–55 mm lens. Edited in ON1 Effects 2019.

Let’s start at the bottom and ask ourselves what is a state, anyway? In the most general sense of the word, it is anything that exists as data in memory when the app is running. However, it is not practical for developers because they don’t need to know how a container is built, for example. We only need to know what is in it.

Thus, a more useful definition of the state would be all data that is essential to rebuild the app’s user interface at any given time.

For my app Notaria, I’m currently trying to implement a way to save a clip from a YouTube video into a note. As an intermediate step, I’m prompting the user to input a start and end time. When the user hits the save button, my app should parse the timestamps to the YouTube player and playback the clip. Since the YouTube player is a stateful widget, I need to update its state to set the start…

--

--

Beyond Boundaries
Beyond the Dev Life

Top Writer in Productivity. Productivity, programming, and Engineering Blogs. Strong focus on tech. Ph.D. student.