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="M9 6C7.34315 6 6 7.34315 6 9V39C6 40.6569 7.34315 42 9 42H39C40.6569 42 42 40.6569 42 39V9C42 7.34315 40.6569 6 39 6H9ZM13 12C12.4477 12 12 12.4477 12 13C12 13.5523 12.4477 14 13 14H14V18H13C12.4477 18 12 18.4477 12 19C12 19.5523 12.4477 20 13 20H17C17.5523 20 18 19.5523 18 19C18 18.4477 17.5523 18 17 18H16V14H17C17.5523 14 18 13.5523 18 13C18 12.4477 17.5523 12 17 12H13ZM25.8557 14.3698C25.548 14.0621 25.156 13.8525 24.7292 13.7677C24.3025 13.6828 23.8601 13.7263 23.4581 13.8929C23.0561 14.0594 22.7126 14.3413 22.4708 14.7031C22.2291 15.0649 22.1 15.4903 22.1 15.9254C22.1 16.3605 22.2291 16.7859 22.4708 17.1476C22.7126 17.5094 23.0561 17.7914 23.4581 17.9579C23.8601 18.1244 24.3025 18.168 24.7292 18.0831C25.156 17.9982 25.548 17.7887 25.8557 17.481C26.2462 17.0905 26.8794 17.0905 27.2699 17.481C27.6604 17.8715 27.6604 18.5047 27.2699 18.8952C26.6825 19.4826 25.9341 19.8826 25.1194 20.0447C24.3047 20.2067 23.4602 20.1236 22.6928 19.8057C21.9253 19.4878 21.2694 18.9495 20.8079 18.2588C20.3464 17.5681 20.1 16.7561 20.1 15.9254C20.1 15.0947 20.3464 14.2827 20.8079 13.592C21.2694 12.9013 21.9253 12.363 22.6928 12.0451C23.4602 11.7272 24.3047 11.644 25.1194 11.8061C25.9341 11.9681 26.6825 12.3682 27.2699 12.9555C27.6604 13.3461 27.6604 13.9792 27.2699 14.3698C26.8794 14.7603 26.2462 14.7603 25.8557 14.3698ZM31 12C30.4477 12 30 12.4477 30 13V19C30 19.5523 30.4477 20 31 20H33C35.2091 20 37 18.2091 37 16C37 13.7909 35.2091 12 33 12H31ZM32 18V14H33C34.1046 14 35 14.8954 35 16C35 17.1046 34.1046 18 33 18H32ZM20.3732 24.0723C20.7519 24.2246 21 24.5918 21 25V35C21 35.5523 20.5523 36 20 36C19.4477 36 19 35.5523 19 35V27.4856L18.7214 27.7759C18.3389 28.1743 17.7059 28.1872 17.3075 27.8047C16.9091 27.4222 16.8961 26.7892 17.2786 26.3908L19.2786 24.3075C19.5613 24.013 19.9946 23.9199 20.3732 24.0723ZM29 25C29 24.5918 28.7519 24.2246 28.3732 24.0723C27.9946 23.9199 27.5613 24.013 27.2786 24.3075L25.2786 26.3908C24.8961 26.7892 24.9091 27.4222 25.3075 27.8047C25.7059 28.1872 26.3389 28.1743 26.7214 27.7759L27 27.4856V35C27 35.5523 27.4477 36 28 36C28.5523 36 29 35.5523 29 35V25Z" fill="black"/>
</svg>
''',
      colorFilter:
          color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
      width: width,
      height: height,
    );