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="M28 35H29.5C37.5081 35 44 28.5082 44 20.5C44 12.4919 37.5081 6.00003 29.5 6.00003H18.5C10.4919 6.00003 4 12.4919 4 20.5C4 28.5082 9 37.5 25.5 41.5L28 42V35ZM26 39.5604V33H29.5C36.4036 33 42 27.4036 42 20.5C42 13.5965 36.4036 8.00003 29.5 8.00003H18.5C11.5964 8.00003 6 13.5965 6 20.5C6 24.07 7.1056 27.8337 10.0613 31.1788C13.0276 34.536 17.9855 37.6143 25.9322 39.5469L26 39.5604Z" fill="black"/>
<path d="M19 18H29V27H19V18Z" fill="black"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M25.0673 14.769C24.8413 14.5783 24.4703 14.4166 24 14.4166C23.5297 14.4166 23.1587 14.5783 22.9327 14.769C22.711 14.956 22.6667 15.1263 22.6667 15.2291V17.9166H25.3333V15.2291C25.3333 15.1263 25.289 14.956 25.0673 14.769ZM24 12.4166C25.841 12.4166 27.3333 13.6758 27.3333 15.2291V19.9166H20.6667V15.2291C20.6667 13.6758 22.159 12.4166 24 12.4166Z" fill="black"/>
</svg>
''',
      colorFilter:
          color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
      width: width,
      height: height,
    );