State<T extends StatefulWidget> class
abstract
The logic and internal state for a StatefulWidget.
State has three main lifecycle hooks and one state function setState.
Framework calls lifecycle hooks on particular events,
-
State.initState - is called when framework decides to inflate the widget. It's called exactly once during lifetime of this widget.
-
State.build - is called when framework wants to build interface for widget. Whatever interface(widgets) this method return will be built. Note that, Framework can call this method multiple times to stay up-to-date with widget's interface description.
-
State.dispose - is called when framework is about to remove widget from the screen.
Apart from these three, State has some additional lifecycle methods that implementations can override:
State.afterMount - Called after widget finishes mounting on screen.
State.afterUpdate - Called after widget finishes re-rendering on screen.
State.afterUnMount - Called after widget has been removed from screen.
State.didUpdateWidget - Called whenever the widget configuration changes.
State.didChangeDependencies- Called when a dependency of this State object changes.
Apart from lifecycle hooks, there is a State.setState function which a widget can use to tell framework to rebuild widget's interface because some internal state of this widget has changed.
It's responsibility of concrete implementation of StatefulWidget to tell framework when to rebuild the interface using State.setState
Constructors
- State()
Properties
- context → BuildContext
-
The location in the tree where this widget builds.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- mounted → bool
-
Whether this State object is currently in a tree.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- widget → T
-
The current configuration.
no setter
Methods
-
afterMount(
) → void - Called after widget finishes mounting on screen.
-
afterUnMount(
) → void - After unMount hook.
-
afterUpdate(
) → void - Called after widget finishes re-rendering to the DOM.
-
build(
BuildContext context) → Widget - Describes the part of the user interface represented by this widget.
-
didChangeDependencies(
) → void - Called when a dependency of this State object changes.
-
didUpdateWidget(
T oldWidget) → void - Called whenever the widget configuration changes.
-
dispose(
) → void -
initState(
) → void - Called when this widget is inserted into the tree.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setState(
VoidCallback callable) → void - Notify the framework that the internal state of this widget has changed.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited