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 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
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.
Check our Flutter app development services page.
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.
For example:
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*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Name
Email
Subject
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.