Lifecycle of Stateful Widget 


The lifecycle of a stateful Widget explains the calling hierarchy of functions and changes in the state of the widget.
Everything in the flutter is a widget.
Basically, the Stateful and stateless are the types of widget in the flutter.

Stateful Widget 

Stateful widgets are widgets that can be changed dynamically on user interaction or input.
It is drawn multiple times during its lifetime.

Life Cycle Methods of StateFul widgets

When we create a stateful widget we have to extend StatefulWidget class and another class that extends the State class.

Create State() :

It is the required method of statefulWidget which must be overridden.

Mounted :

This property set to true once the state object is created.
This property is useful to check whether a state is in the widget tree.
We can avoid errors by checking this property while rebuilding the widget or calling the setState function.


It is the first calling method of the state.
It is called only once when we create a widget.
We can use this method for initializing purposes.


This method is called immediately after initState method.
This method is rarely used because the build method is always called after this method.
It is also called when a dependency of this State object changes.


This is a required method and is called many times during the lifecycle.
This method is also called after didChangeDependencies() method.

didUpdateWidget() :

This method is called at the time of widget rebuild and the parent widget changes its configuration.
It gives an old widget as an argument that can be used for widget comparison.
Build method will call just after it.

setState() :

this method is called by developers when there is a requirement to rebuild the widget.
Framework called this function itself.
setState() notify to the framework that the widget should be rebuilt as data has been changed.

Dispose() :

This method is called when the state object is removed from the Widget tree.
this method can be used for cleaning purposes like removing listener etc.

mounted (false):

After dispose() this property is set to false.
If setState is called when this property is false will throw to error.


In this blog, we have discussed about the lifecycle of the Stateful Widget.

I hope this blog will helps you.

Thank you for reading!!

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


  • wes
    thank you for this article
    • Pankaj Tyagi (Moderator)
      Thanks for your comment.
  • css.php

    Webkul is a truly trusted and supported IT Company to develop business ideas for e-commerce. They provide professional support after deploying the solution to production and be responsible to act for fixing the reported issues or system errors. We highly encourage to deal with Webkul for business development.

    Hussein Zawia

    Hussein Zawia

    Co-founder, 24Dokan

    Talk to Sales


    Live Chat
    Start a Project

      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home