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="M4.0627 21H19.8984C20.6378 21 21.1215 20.2253 20.7969 19.561L12.6528 2.89183C12.2828 2.13455 11.1995 2.14655 10.8463 2.91184L3.1547 19.581C2.84896 20.2436 3.33295 21 4.0627 21ZM11.8855 12.25C11.1337 12.25 10.7458 12.7426 10.7458 13.0989C10.7458 13.5131 10.41 13.8489 9.9958 13.8489C9.58158 13.8489 9.2458 13.5131 9.2458 13.0989C9.2458 11.6891 10.5499 10.75 11.8855 10.75C13.221 10.75 14.5251 11.6891 14.5251 13.0989C14.5251 14.2855 13.5987 15.1061 12.4901 15.3626V15.4973C12.4901 15.9116 12.1543 16.2473 11.7401 16.2473C11.3259 16.2473 10.9901 15.9116 10.9901 15.4973V14.7324C10.9901 14.2916 11.3471 13.9529 11.7656 13.9477C12.6657 13.9367 13.0251 13.415 13.0251 13.0989C13.0251 12.7426 12.6372 12.25 11.8855 12.25ZM12.4999 17.6748C12.4999 18.089 12.1642 18.4248 11.7499 18.4248C11.3357 18.4248 10.9999 18.089 10.9999 17.6748C10.9999 17.2606 11.3357 16.9248 11.7499 16.9248C12.1642 16.9248 12.4999 17.2606 12.4999 17.6748Z" fill="black"/>
</svg>
''',
      colorFilter:
          color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
      width: width,
      height: height,
    );