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="M16.3404 28.3239L18.3122 28.6586L17.2938 34.657L22.5988 31.8395C23.4753 31.374 24.5247 31.374 25.4012 31.8395L30.7062 34.657L29.6878 28.6587C29.5237 27.6921 29.8396 26.7012 30.5425 26.009L34.8751 21.7427L28.9065 20.8665C27.923 20.7222 27.0826 20.0998 26.6507 19.2157L28.4477 18.3378C28.5926 18.6345 28.8728 18.8402 29.1969 18.8877L37.1469 20.0547C37.9631 20.1745 38.289 21.1878 37.6984 21.7694L31.9457 27.4341C31.7112 27.665 31.6042 27.9978 31.6596 28.3239L33.0176 36.3226C33.157 37.1438 32.3038 37.77 31.5737 37.3823L24.4631 33.6058C24.1732 33.4519 23.8268 33.4519 23.5369 33.6058L16.4263 37.3823C15.6962 37.77 14.843 37.1438 14.9824 36.3226L16.3404 28.3239ZM10.3016 21.7694C9.71099 21.1878 10.0369 20.1745 10.8531 20.0547L18.8031 18.8877C19.1272 18.8402 19.4074 18.6345 19.5523 18.3378L21.3493 19.2157C20.9174 20.0998 20.077 20.7222 19.0936 20.8665L13.1249 21.7427L17.4575 26.009C18.1604 26.7012 18.4763 27.6921 18.3122 28.6586L16.3404 28.3239C16.3958 27.9978 16.2888 27.665 16.0543 27.4341L10.3016 21.7694ZM24 13.7901L26.6507 19.2157L28.4477 18.3378L24.8923 11.0604C24.5273 10.3132 23.4727 10.3132 23.1077 11.0604L19.5523 18.3378L21.3493 19.2157L24 13.7901Z" fill="black"/>
</svg>
''',
      colorFilter:
          color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
      width: width,
      height: height,
    );