build method

  1. @override
Widget build(
  1. BuildContext context
)
override

Describes the part of the user interface represented by this widget.

The framework calls this method when this widget is inserted into the tree in a given BuildContext and when the dependencies of this widget change (e.g., an InheritedWidget referenced by this widget changes). This method can potentially be called in every frame and should not have any side effects beyond building a widget.

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 and from the given BuildContext.

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. A given widget might be built with multiple different BuildContext arguments over time if the widget is moved around the tree or if the widget is inserted into the tree in multiple places at once.

The implementation of this method must only depend on:

If a widget's build method is to depend on anything else, use a StatefulWidget instead.

See also:

  • StatelessWidget, which contains the discussion on performance considerations.

Implementation

@override
widgets.Widget build(widgets.BuildContext context) => SvgPicture.string(
      '''
<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M16 5H29L38 14V37C38 38.1046 37.1046 39 36 39H16C14.8954 39 14 38.1046 14 37V7C14 5.89543 14.8954 5 16 5ZM35 14L29 8V13C29 13.5523 29.4477 14 30 14H35ZM21.2929 20.2929C21.6834 19.9024 22.3166 19.9024 22.7071 20.2929L26 23.5858L29.2929 20.2929C29.6834 19.9024 30.3166 19.9024 30.7071 20.2929C31.0976 20.6834 31.0976 21.3166 30.7071 21.7071L27.4142 25L30.7071 28.2929C31.0976 28.6834 31.0976 29.3166 30.7071 29.7071C30.3166 30.0976 29.6834 30.0976 29.2929 29.7071L26 26.4142L22.7071 29.7071C22.3166 30.0976 21.6834 30.0976 21.2929 29.7071C20.9024 29.3166 20.9024 28.6834 21.2929 28.2929L24.5858 25L21.2929 21.7071C20.9024 21.3166 20.9024 20.6834 21.2929 20.2929Z" fill="black"/>
<path d="M12 11H10V38C10 40.7614 12.2386 43 15 43H34V41H15C13.3431 41 12 39.6569 12 38V11Z" fill="black"/>
</svg>
''',
      colorFilter:
          color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
      width: width,
      height: height,
    );