Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 22.214.171.124 release ready!
Updated 30 January 2024
In this blog, we are going to learn about the Widget Lifecycle in the flutter. We will cover the implementation of the Widget Lifecycle in the flutter in this blog.
You may become more familiar with Flutter app development from Mobikul.
So let’s get started.
There are two types of widgets.
A Stateless Widget cannot have states change over time. There are no data changes inside the stateless widget.
The build function only runs once inside the Widget when it is created.
So, If we want to change something on the screen, it can not reflect over the screen because it is completely stateless. It means it cannot rebuild itself when anything gets changed.
It destroys the widget completely and then creates a new instance of some different data.
Stateful Widget changes over time. E.g., If we have some kind of counter then it will be changed over time.
The changes are done inside the setState() when we change the data inside this method, which will trigger the build function.
When we build a new Stateful Widget, it immediately calls createState() right away and this override method must exist.
Once the State object has been created, the first method call is initState()
It is called only once when the widget is created. It Subscribes to streams or any object that could change our widget data.
This method calls immediately after the initState() the first time the widget is built.
This method is to build the widget tree.
Also, it is triggered every time when we use setState() to change the data.
If the parent widget changes and has to rebuild this widget (because it needs to give it different data), but it is being rebuilt with the same runtime Type, then this method is called.
This is because Flutter is re-using the state, which is long-lived. In this case, you may want to initialize some data again, as you would in initState().
The setState() is called often from the flutter framework itself and from the developer.
It is used to notify the framework that “data has changed”
The ‘deactivate()’ is used when the State is removed from the tree.
But before the current frame change can be re-inserted into another part of the tree
The ‘dispose()’ is used when the state/widget is removed permanently.
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.