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="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M11.636 1.8335L9.90393 2.8335L10.6161 4.06696L9.86603 4.5C9.38773 4.77614 9.22386 5.38773 9.5 5.86603L10.2791 7.21547C7.26184 7.98529 5 10.7289 5 14C5 16.5424 6.34795 18.7738 8.36803 20H5V22H19V20H15.3832C15.8727 19.6981 16.3216 19.3403 16.7212 18.9441C17.3026 18.3677 17.7018 17.6812 18.0018 17H20V15H13V17H15.7397C15.6117 17.1923 15.471 17.3673 15.3131 17.5238C14.4015 18.4277 13.214 19 11.9507 19C9.22427 19 7 16.7692 7 14C7 11.4684 8.90586 9.37229 11.3351 9.04455L13.9528 13.5784L15.6104 12.6214L16.3412 13.8871L18.0733 12.8871L17.3425 11.6214L19.1489 10.5784L14.6962 2.86603C14.42 2.38773 13.8084 2.22386 13.3301 2.5L12.3481 3.06696L11.636 1.8335ZM14.6848 10.8464L11.7321 5.73205L13.4641 4.73205L16.4169 9.84638L14.6848 10.8464Z" fill="black"/>
</svg>
''',
      colorFilter:
          color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
      width: width,
      height: height,
    );