SlideShare a Scribd company logo
Widget Lifecycle
in Flutter
A StatefulWidget has a complete
widget lifecycle and goes through
the following stages:
createState(): In stateful widget, the 1st method
that is called is createState(). The createState()
method returns the instate of the state of the
Stateful widget.


initState(): This is the first method called after the
constructor of the Stateful Widget. It is called
whenever the screen or widget is added to the
widget tree! Here you can initialize your variables,
objects, streams, AnimationController, etc.


didChangeDependencies(): It is always called for
the 1st time after initState() . You can include few
functionalities like API calls based on parent data
changes, variable re-initializations, etc.


build(): The build method is the one that shows and
renders the UI part to the user. Whenever you want
to update your UI or if you click hot-reload, the
Flutter framework rebuilds the build() method!
didUpdateWidget(Widget oldWidget): If the parent widget
changes its properties or configurations, and the parent
wants to rebuild the child widget, with the same Runtime
Type, then didUpdateWidget is triggered. This unsubscribes
to the old widget and subscribes to the configuration changes
of the new widget!


setState(): This method notifies the Flutter framework that
the internal state of the widget tree has been modified, and
the build method needs to be rendered again.


deactivate(): This method is called when the widget is no
longer attached to the Widget Tree but it might be attached
in a later stage.


dispose(): This is called when the State object or Widget is
removed permanently from the Widget Tree. Here you can
unsubscribe streams, cancel timers, dispose animation
controllers, close files, etc. In other words, you can release all
the resources in this method.
StatefulWidget.createState()
initState
didChangeDepenencies
build setState
didUpdateWidget
receives a new
configuration invoke
deactivate
dispose
hello@somniosoftware.com
Leave a comment


Save for later

More Related Content

More from EugeniaGallo1

TextField vs TextFormField
TextField vs TextFormFieldTextField vs TextFormField
TextField vs TextFormField
EugeniaGallo1
 
Using Regex to validate the email
Using Regex to validate the emailUsing Regex to validate the email
Using Regex to validate the email
EugeniaGallo1
 
GestureDetector vs InkWell
GestureDetector vs InkWellGestureDetector vs InkWell
GestureDetector vs InkWell
EugeniaGallo1
 
Difference between Container and SizedBox
Difference between Container and SizedBoxDifference between Container and SizedBox
Difference between Container and SizedBox
EugeniaGallo1
 
Difference between Container and SizedBox
Difference between Container and SizedBoxDifference between Container and SizedBox
Difference between Container and SizedBox
EugeniaGallo1
 
Flutter Sessions #4
Flutter Sessions #4Flutter Sessions #4
Flutter Sessions #4
EugeniaGallo1
 
Dash: Our loyal office companion.pdf
Dash: Our loyal office companion.pdfDash: Our loyal office companion.pdf
Dash: Our loyal office companion.pdf
EugeniaGallo1
 
6 App Marketing Strategies you should include
6 App Marketing Strategies you should include6 App Marketing Strategies you should include
6 App Marketing Strategies you should include
EugeniaGallo1
 
6 App Marketing Strategies you should include.pdf
6 App Marketing Strategies you should include.pdf6 App Marketing Strategies you should include.pdf
6 App Marketing Strategies you should include.pdf
EugeniaGallo1
 
Trip to Oslo and London
Trip to Oslo and LondonTrip to Oslo and London
Trip to Oslo and London
EugeniaGallo1
 

More from EugeniaGallo1 (10)

TextField vs TextFormField
TextField vs TextFormFieldTextField vs TextFormField
TextField vs TextFormField
 
Using Regex to validate the email
Using Regex to validate the emailUsing Regex to validate the email
Using Regex to validate the email
 
GestureDetector vs InkWell
GestureDetector vs InkWellGestureDetector vs InkWell
GestureDetector vs InkWell
 
Difference between Container and SizedBox
Difference between Container and SizedBoxDifference between Container and SizedBox
Difference between Container and SizedBox
 
Difference between Container and SizedBox
Difference between Container and SizedBoxDifference between Container and SizedBox
Difference between Container and SizedBox
 
Flutter Sessions #4
Flutter Sessions #4Flutter Sessions #4
Flutter Sessions #4
 
Dash: Our loyal office companion.pdf
Dash: Our loyal office companion.pdfDash: Our loyal office companion.pdf
Dash: Our loyal office companion.pdf
 
6 App Marketing Strategies you should include
6 App Marketing Strategies you should include6 App Marketing Strategies you should include
6 App Marketing Strategies you should include
 
6 App Marketing Strategies you should include.pdf
6 App Marketing Strategies you should include.pdf6 App Marketing Strategies you should include.pdf
6 App Marketing Strategies you should include.pdf
 
Trip to Oslo and London
Trip to Oslo and LondonTrip to Oslo and London
Trip to Oslo and London
 

Widget Lifecycle in Flutter

  • 1. Widget Lifecycle in Flutter A StatefulWidget has a complete widget lifecycle and goes through the following stages:
  • 2. createState(): In stateful widget, the 1st method that is called is createState(). The createState() method returns the instate of the state of the Stateful widget. initState(): This is the first method called after the constructor of the Stateful Widget. It is called whenever the screen or widget is added to the widget tree! Here you can initialize your variables, objects, streams, AnimationController, etc. didChangeDependencies(): It is always called for the 1st time after initState() . You can include few functionalities like API calls based on parent data changes, variable re-initializations, etc. build(): The build method is the one that shows and renders the UI part to the user. Whenever you want to update your UI or if you click hot-reload, the Flutter framework rebuilds the build() method!
  • 3. didUpdateWidget(Widget oldWidget): If the parent widget changes its properties or configurations, and the parent wants to rebuild the child widget, with the same Runtime Type, then didUpdateWidget is triggered. This unsubscribes to the old widget and subscribes to the configuration changes of the new widget! setState(): This method notifies the Flutter framework that the internal state of the widget tree has been modified, and the build method needs to be rendered again. deactivate(): This method is called when the widget is no longer attached to the Widget Tree but it might be attached in a later stage. dispose(): This is called when the State object or Widget is removed permanently from the Widget Tree. Here you can unsubscribe streams, cancel timers, dispose animation controllers, close files, etc. In other words, you can release all the resources in this method.