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="M2.25 5C2.25 3.48122 3.48122 2.25 5 2.25H19C20.5188 2.25 21.75 3.48122 21.75 5V15C21.75 16.5188 20.5188 17.75 19 17.75H7.96125C7.58154 17.75 7.2224 17.9226 6.98516 18.2191L4.65418 21.1328C3.85702 22.1293 2.25 21.5657 2.25 20.2895V5ZM9.48099 10.75C9.42305 10.8439 9.35472 10.9437 9.275 11.05C8.93823 11.499 8.47947 11.9599 7.96967 12.4697C7.67678 12.7626 7.67678 13.2374 7.96967 13.5303C8.26256 13.8232 8.73744 13.8232 9.03033 13.5303L9.05192 13.5087C9.53637 13.0243 10.0678 12.4929 10.475 11.95C10.8823 11.4069 11.25 10.7447 11.25 10V8C11.25 7.03352 10.4665 6.25 9.5 6.25H8.5C7.53351 6.25 6.75 7.03351 6.75 8V9C6.75 9.96649 7.53351 10.75 8.5 10.75H9.48099ZM15.275 11.05C15.3547 10.9437 15.4231 10.8439 15.481 10.75H14.5C13.5335 10.75 12.75 9.96648 12.75 9V8C12.75 7.03352 13.5335 6.25 14.5 6.25H15.5C16.4665 6.25 17.25 7.03352 17.25 8V10C17.25 10.7447 16.8823 11.4069 16.475 11.95C16.0678 12.4929 15.5364 13.0243 15.0519 13.5087L15.0303 13.5303C14.7374 13.8232 14.2626 13.8232 13.9697 13.5303C13.6768 13.2374 13.6768 12.7626 13.9697 12.4697C14.4795 11.9599 14.9382 11.499 15.275 11.05Z" fill="currentColor"/>
</svg>
''',
      colorFilter:
          color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
      width: width,
      height: height,
    );