From the course: Flutter Essential Training: Build for Multiple Platforms
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Lifecycle of a stateful widget - Flutter Tutorial
From the course: Flutter Essential Training: Build for Multiple Platforms
Lifecycle of a stateful widget
- [Instructor] Let's go back to the Stateful widget signature and notice our State class again. Once the createState has created the State object a BuildContext is associated with the State object. Now, if you check the documentation you will read that the BuildContext is nothing but the location in the tree where this widget builds. Now, once the BuildContext associated you can see that this value, mounted, will be true. So you can use this logic that requires you to work with this context maybe, or if you want to execute something only after the State object is successfully created. Or even while doing setState. So here you could do something like if mounted, then you do the setState. This is a good way to make sure you're not performing setState on an unmounted State to avoid any runtime crashes. Moving forward, the State class overrides a bunch of lifecycle methods, but the two most important widget lifecycle…
Contents
-
-
-
-
-
-
What is state?1m 55s
-
(Locked)
Writing your first stateful widget7m 17s
-
(Locked)
Widget variables vs. state variables3m 26s
-
(Locked)
When to use stateless or stateful?1m 51s
-
(Locked)
Lifecycle of a stateful widget3m 44s
-
(Locked)
Stateful hot reload3m 22s
-
(Locked)
Learning about buttons6m 50s
-
(Locked)
Taps and gesture detection3m 47s
-
(Locked)
Getting inputs from the user7m 40s
-
(Locked)
Validating user inputs7m 55s
-
(Locked)
Creating multiline text fields6m 46s
-
(Locked)
Navigating from one screen to another5m 41s
-
(Locked)
Passing data with navigation2m 7s
-
(Locked)
Navigating via named routes4m 8s
-
(Locked)
Replacing routes using Navigator5m 16s
-
-
-
-
-