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="M20 4C18.3431 4 17 5.34315 17 7H14C12.3431 7 11 8.34315 11 10V38C11 39.6569 12.3431 41 14 41H26V39H14C13.4477 39 13 38.5523 13 38V10C13 9.44772 13.4477 9 14 9H17C17 10.6569 18.3431 12 20 12H28C29.6569 12 31 10.6569 31 9H34C34.5523 9 35 9.44772 35 10V25H37V10C37 8.34315 35.6569 7 34 7H31C31 5.34315 29.6569 4 28 4H20ZM19 7C19 6.44772 19.4477 6 20 6H28C28.5523 6 29 6.44772 29 7V9C29 9.55228 28.5523 10 28 10H20C19.4477 10 19 9.55228 19 9V7ZM23 19V16H25V19H28V21H25V24H23V21H20V19H23ZM27 28C27 27.4477 27.4477 27 28 27H40C40.5523 27 41 27.4477 41 28V34.7889C41 37.1294 39.8303 39.315 37.8829 40.6133L34.5547 42.8321C34.2188 43.056 33.7812 43.056 33.4453 42.8321L30.1171 40.6133C28.1697 39.315 27 37.1294 27 34.7889V28ZM29 29V34.7889C29 36.4607 29.8355 38.0218 31.2265 38.9492L34 40.7981L36.7735 38.9492C38.1645 38.0218 39 36.4607 39 34.7889V29H29ZM33.7071 36.7072L37.7071 32.7072L36.2928 31.293L33 34.5859L31.7071 33.293L30.2928 34.7072L32.2928 36.7072C32.6834 37.0977 33.3165 37.0977 33.7071 36.7072Z" fill="black"/>
</svg>
''',
      colorFilter:
          color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
      width: width,
      height: height,
    );