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 d="M28 8C28 10.2091 26.2091 12 24 12C21.7909 12 20 10.2091 20 8C20 5.79086 21.7909 4 24 4C26.2091 4 28 5.79086 28 8Z" fill="black"/>
<path d="M18 18.8206C17.7833 19.3328 17.5909 20.0103 17.4363 20.815C17.0295 22.9313 17 25.273 17 26C17 27.1046 16.1046 28 15 28C13.8954 28 13 27.1046 13 26C13 25.227 13.026 22.5687 13.5082 20.06C13.7458 18.8236 14.1243 17.4534 14.773 16.3428C15.4241 15.2281 16.595 14 18.4444 14H29.5556C31.405 14 32.5759 15.2281 33.227 16.3428C33.8757 17.4534 34.2542 18.8236 34.4918 20.06C34.974 22.5687 35 25.227 35 26C35 27.1046 34.1046 28 33 28C31.8954 28 31 27.1046 31 26C31 25.273 30.9705 22.9313 30.5637 20.815C30.4091 20.0103 30.2167 19.3328 30 18.8206V42C30 43.0747 29.1507 43.9573 28.0768 43.9985C27.0028 44.0398 26.0883 43.2249 26.0059 42.1534L25.0059 29.1534C25.002 29.1022 25 29.051 25 29H23C23 29.051 22.998 29.1022 22.9941 29.1534L21.9941 42.1534C21.9117 43.2249 20.9972 44.0398 19.9232 43.9985C18.8493 43.9573 18 43.0747 18 42V18.8206Z" fill="black"/>
</svg>
''',
      colorFilter:
          color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
      width: width,
      height: height,
    );