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" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M20.4 2.25C21.1456 2.25 21.75 2.85442 21.75 3.6V20.4C21.75 21.1456 21.1456 21.75 20.4 21.75H3.6C2.85441 21.75 2.25 21.1456 2.25 20.4L2.25 3.6C2.25 2.85441 2.85442 2.25 3.6 2.25H20.4ZM12.0303 11.4697L8.53033 7.96967C8.23744 7.67678 7.76256 7.67678 7.46967 7.96967C7.17678 8.26256 7.17678 8.73744 7.46967 9.03033L10.4393 12L7.46967 14.9697C7.17678 15.2626 7.17678 15.7374 7.46967 16.0303C7.76256 16.3232 8.23744 16.3232 8.53033 16.0303L12.0303 12.5303C12.3232 12.2374 12.3232 11.7626 12.0303 11.4697ZM14.5303 7.96967L18.0303 11.4697C18.3232 11.7626 18.3232 12.2374 18.0303 12.5303L14.5303 16.0303C14.2374 16.3232 13.7626 16.3232 13.4697 16.0303C13.1768 15.7374 13.1768 15.2626 13.4697 14.9697L16.4393 12L13.4697 9.03033C13.1768 8.73744 13.1768 8.26256 13.4697 7.96967C13.7626 7.67678 14.2374 7.67678 14.5303 7.96967Z" fill="currentColor"/>
</svg>
''',
      colorFilter:
          color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
      width: width,
      height: height,
    );