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="M13 12C13 10.3431 14.3431 9 16 9L26 9C30.9706 9 35 13.0294 35 18C35 21.4119 33.1017 24.3785 30.3064 25.9045L34.6833 34.6584C35.4242 36.1403 34.8236 37.9423 33.3416 38.6833C31.8597 39.4242 30.0577 38.8236 29.3167 37.3416L24.1459 27L19 27L19 36C19 37.6569 17.6569 39 16 39C14.3431 39 13 37.6569 13 36L13 12ZM16 11C15.4477 11 15 11.4477 15 12L15 36C15 36.5523 15.4477 37 16 37C16.5523 37 17 36.5523 17 36L17 26C17 25.4477 17.4477 25 18 25L24.7639 25C25.1427 25 25.489 25.214 25.6584 25.5528L31.1056 36.4472C31.3526 36.9412 31.9532 37.1414 32.4472 36.8944C32.9412 36.6474 33.1414 36.0468 32.8944 35.5528L28.06 25.884C27.9348 25.6335 27.9203 25.342 28.0201 25.0804C28.1199 24.8188 28.3248 24.611 28.585 24.5075C31.1732 23.4784 33 20.9513 33 18C33 14.134 29.866 11 26 11L16 11ZM17 14C17 13.4477 17.4477 13 18 13L26 13C28.7614 13 31 15.2386 31 18C31 20.7614 28.7614 23 26 23L18 23C17.4477 23 17 22.5523 17 22L17 14ZM19 15L19 21L26 21C27.6569 21 29 19.6569 29 18C29 16.3431 27.6569 15 26 15L19 15Z" fill="black"/>
</svg>
''',
      colorFilter:
          color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
      width: width,
      height: height,
    );