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 12.5546C13.5668 12.7102 13.75 12.9651 13.75 13.5C13.75 14.3615 13.5136 14.7365 13.2891 14.9226C13.036 15.1324 12.6238 15.25 12 15.25C11.3762 15.25 10.964 15.1324 10.7109 14.9226C10.4864 14.7365 10.25 14.3615 10.25 13.5C10.25 12.9651 10.4332 12.7102 10.6585 12.5546C10.9312 12.3662 11.3787 12.25 12 12.25C12.6213 12.25 13.0688 12.3662 13.3415 12.5546ZM14.194 11.3204C13.5619 10.8838 12.7594 10.75 12 10.75C11.4326 10.75 10.8412 10.8247 10.3147 11.0445C10.315 11.0427 10.3152 11.0409 10.3154 11.0391C10.3793 10.4851 10.4996 10.082 10.6934 9.78057C11.0407 9.24031 11.8186 8.75 14 8.75C14.4142 8.75 14.75 8.41421 14.75 8C14.75 7.58579 14.4142 7.25 14 7.25C11.6814 7.25 10.2093 7.75969 9.43162 8.96943C9.06291 9.54297 8.90195 10.2024 8.82526 10.8672C8.74998 11.5196 8.74999 12.2433 8.75 12.9721V13C8.75 13.0541 8.75572 13.1068 8.76658 13.1576C8.75557 13.2684 8.75 13.3826 8.75 13.5C8.75 14.6385 9.07325 15.5135 9.75361 16.0774C10.4053 16.6176 11.2431 16.75 12 16.75C12.7569 16.75 13.5947 16.6176 14.2464 16.0774C14.9267 15.5135 15.25 14.6385 15.25 13.5C15.25 12.5349 14.8736 11.7898 14.194 11.3204Z" fill="currentColor"/>
</svg>
''',
      colorFilter:
          color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
      width: width,
      height: height,
    );