Android App Development
iOS 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 126.96.36.199 release ready!
In this article, we are going to learn about the StatefulBuilder widget in flutter and will also learn when and where to use this widget.
StatefulBuilder is a widget having a mutable state (whose state can be changed). What makes it’s special is that it only rebuilds the particular widget that is wrapped under the Stateful Builder.
This widget provides a state setter method that is responsible for the rebuilding of the widget.
The widgets that you want to update should be kept inside this widget.
The Below code will not work, i.e the text in the Text widget will not update because it needs to be wrapped in this widget.
What you need to do here is this:
Now the above code will work perfectly.
We cannot replace the stateful widget with this widget because Flutter only preserves associated states that we provide in stateful widgets.
If we use a stateful builder widget and store any state in instance variables in the stateless widget it may be lost at any time as the constructor for the stateless widget may be called multiple times, just like the build method.
Now we know how to use the stateful builder widget in flutter. We also know why we cannot replace the stateful widget with this widget.
To read more blogs on flutter head over here.
Reference: Can Stateful Builder Step into the shoes of Stateful Widget?
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.
Excellent work, fast, good quality and understood the brief perfectly! Quick responses developing the project and very good cooperation. I suggest to anyone.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.