- override
Called when this object is inserted into the tree.
The framework will call this method exactly once for each State
object
it creates.
Override this method to perform initialization that depends on the
location at which this object was inserted into the tree (i.e., context
)
or on the widget used to configure this object (i.e., config
).
If a State
's build
method depends on an object that can itself change
state, for example a ChangeNotifier
or Stream
, or some other object to
which one can subscribe to receive notifications, then the State
should
subscribe to that object during initState
, unsubscribe from the old
object and subscribe to the new object when it changes in
didUpdateConfig
, and then unsubscribe from the object in dispose
.
You cannot use BuildContext.inheritFromWidgetOfExactType
from this
method. However, dependenciesChanged
will be called immediately
following this method, and BuildContext.inheritFromWidgetOfExactType
can
be used there.
If you override this, make sure your method starts with a call to super.initState().
Source
@override void initState() { super.initState(); _appBarController = new AnimationController(vsync: this); // Use an explicit identifier to guard against the possibility that the // Scaffold's key is recreated by the Widget that creates the Scaffold. List<double> scrollValues = PageStorage.of(context)?.readState(context, identifier: _kScaffoldStorageIdentifier ); if (scrollValues != null) { assert(scrollValues.length == 2); _scrollOffset = scrollValues[0]; _scrollOffsetDelta = scrollValues[1]; } }