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="M21.2308 37.1538C21.6966 38.2718 22.7889 39 24.0001 39C25.2112 39 26.3035 38.2718 26.7693 37.1538L36.7693 13.1538C37.4065 11.6244 36.6833 9.86802 35.1539 9.23077C33.6245 8.59352 31.8681 9.31675 31.2308 10.8462L24.0001 28.2L16.7693 10.8462C16.132 9.31675 14.3756 8.59352 12.8462 9.23077C11.3168 9.86802 10.5936 11.6244 11.2308 13.1538L21.2308 37.1538ZM24.0001 37C23.5963 37 23.2322 36.7573 23.077 36.3846L13.077 12.3846C12.8646 11.8748 13.1056 11.2893 13.6154 11.0769C14.1252 10.8645 14.7107 11.1056 14.9231 11.6154L23.077 31.1846C23.2322 31.5573 23.5963 31.8 24.0001 31.8C24.4038 31.8 24.7679 31.5573 24.9231 31.1846L33.077 11.6154C33.2894 11.1056 33.8749 10.8645 34.3847 11.0769C34.8945 11.2893 35.1355 11.8748 34.9231 12.3846L24.9231 36.3846C24.7679 36.7573 24.4038 37 24.0001 37Z" fill="black"/>
</svg>
''',
      colorFilter:
          color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
      width: width,
      height: height,
    );