Stage 2 · Lesson 6 of 10
StatefulWidget and setState
A StatefulWidget keeps values that can change in its State object. Calling setState tells to rebuild that with the new values. Use it for local UI state that belongs to one widget: a toggle that shows or hides a password, the selected tab in a small control, or a counter.
Controllers such as TextEditingController and AnimationController live in State too. Create them in initState and release them in dispose. Wrap only the smallest change in setState, and do slow work outside it. The next stage covers state that several screens share.
Common trapchanging a variable without setState, so nothing redraws, or calling setState after the widget has been disposed.
A question to check yourself, an AI practice session and 2 cheat sheet entries come with the full roadmap. Unlock
Resources for this stage
Start with
- GuideFreeFlutter Documentation
Google
Do the first Flutter app codelab, then the layout, constraints and lists pages