- override
Describes the part of the user interface represented by this widget.
The framework calls this method in a number of different situations:
- After calling
initState
. - After calling
didUpdateConfig
. - After receiving a call to
setState
. - After a dependency of this
State
object changes (e.g., anInheritedWidget
referenced by the previousbuild
changes). - After calling
deactivate
and then reinserting theState
object into the tree at another location.
The framework replaces the subtree below this widget with the widget
returned by this method, either by updating the existing subtree or by
removing the subtree and inflating a new subtree, depending on whether the
widget returned by this method can update the root of the existing
subtree, as determined by calling Widget.canUpdate
.
Typically implementations return a newly created constellation of widgets
that are configured with information from this widget's constructor, the
given BuildContext
, and the internal state of this State
object.
The given BuildContext
contains information about the location in the
tree at which this widget is being built. For example, the context
provides the set of inherited widgets for this location in the tree. The
BuildContext
argument is always the same as the context
property of
this State
object and will remain the same for the lifetime of this
object. The BuildContext
argument is provided redundantly here so that
this method matches the signature for a WidgetBuilder
.
Source
@override Widget build(BuildContext context) { // These lists are filled backwards. For the offstage children that // does not matter since they aren't rendered, but for the onstage // children we reverse the list below before adding it to the tree. final List<Widget> onstageChildren = <Widget>[]; final List<Widget> offstageChildren = <Widget>[]; bool onstage = true; for (int i = _entries.length - 1; i >= 0; i -= 1) { OverlayEntry entry = _entries[i]; if (onstage) { onstageChildren.add(new _OverlayEntry(entry)); if (entry.opaque) onstage = false; } else if (entry.maintainState) { offstageChildren.add(new TickerMode(enabled: false, child: new _OverlayEntry(entry))); } } return new _Theatre( onstage: new Stack(children: onstageChildren.reversed.toList(growable: false)), offstage: offstageChildren, ); }