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 d="M21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12C3 7.02944 7.02944 3 12 3C16.9706 3 21 7.02944 21 12ZM10.75 9.8C10.75 9.63776 11.0339 9 12.0591 9C13.0843 9 13.3682 9.63776 13.3682 9.8C13.3682 9.8667 13.1623 10.5837 11.8405 10.5998C10.7462 10.6131 9.80455 11.4983 9.80455 12.66V14C9.80455 14.5844 10.0552 15.1103 10.4549 15.4759C10.0236 15.8428 9.75 16.3894 9.75 17C9.75 18.1046 10.6454 19 11.75 19C12.8546 19 13.75 18.1046 13.75 17C13.75 16.4156 13.4993 15.8897 13.0997 15.5241C13.4608 15.2169 13.7113 14.7838 13.7833 14.2926C15.7109 13.6698 17.3682 12.0997 17.3682 9.8C17.3682 6.83861 14.6528 5 12.0591 5C9.46538 5 6.75 6.83861 6.75 9.8C6.75 10.9046 7.64543 11.8 8.75 11.8C9.85457 11.8 10.75 10.9046 10.75 9.8Z" fill="black" stroke="black" stroke-width="2"/>
</svg>
''',
      colorFilter:
          color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
      width: width,
      height: height,
    );