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 3.6C2.25 2.85441 2.85442 2.25 3.6 2.25H20.4C21.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.4V3.6ZM13.3415 13.0546C13.5668 13.2102 13.75 13.4651 13.75 14C13.75 14.5349 13.5668 14.7898 13.3415 14.9454C13.0688 15.1338 12.6213 15.25 12 15.25C11.3787 15.25 10.9312 15.1338 10.6585 14.9454C10.4332 14.7898 10.25 14.5349 10.25 14C10.25 13.4651 10.4332 13.2102 10.6585 13.0546C10.9312 12.8662 11.3787 12.75 12 12.75C12.6213 12.75 13.0688 12.8662 13.3415 13.0546ZM9.57592 12C9.042 12.4706 8.75 13.15 8.75 14C8.75 14.9651 9.12642 15.7102 9.80598 16.1796C10.4381 16.6162 11.2406 16.75 12 16.75C12.7594 16.75 13.5619 16.6162 14.194 16.1796C14.8736 15.7102 15.25 14.9651 15.25 14C15.25 13.15 14.958 12.4706 14.4241 12C14.958 11.5294 15.25 10.85 15.25 10C15.25 9.03486 14.8736 8.28981 14.194 7.8204C13.5619 7.38377 12.7594 7.25 12 7.25C11.2406 7.25 10.4381 7.38377 9.80598 7.8204C9.12642 8.28981 8.75 9.03486 8.75 10C8.75 10.85 9.042 11.5294 9.57592 12ZM12 11.25C12.6213 11.25 13.0688 11.1338 13.3415 10.9454C13.5668 10.7898 13.75 10.5349 13.75 10C13.75 9.46514 13.5668 9.21019 13.3415 9.0546C13.0688 8.86623 12.6213 8.75 12 8.75C11.3787 8.75 10.9312 8.86623 10.6585 9.0546C10.4332 9.21019 10.25 9.46514 10.25 10C10.25 10.5349 10.4332 10.7898 10.6585 10.9454C10.9312 11.1338 11.3787 11.25 12 11.25Z" fill="currentColor"/>
</svg>
''',
      colorFilter:
          color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
      width: width,
      height: height,
    );