build method
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:
- the fields of the widget, which themselves must not change over time, and
- any ambient state obtained from the
context
using BuildContext.dependOnInheritedWidgetOfExactType.
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 21.75C21.1456 21.75 21.75 21.1456 21.75 20.4V3.6C21.75 2.85442 21.1456 2.25 20.4 2.25H3.6C2.85442 2.25 2.25 2.85441 2.25 3.6V20.4C2.25 21.1456 2.85441 21.75 3.6 21.75H20.4ZM7.42424 12.4802C8.2529 13.4746 8.43933 14.3968 8.34791 15.216C8.25273 16.069 7.84772 16.8767 7.37627 17.5842C7.14658 17.9289 7.23981 18.3945 7.5845 18.6242C7.9292 18.8539 8.39483 18.7607 8.62452 18.416C9.15261 17.6235 9.70502 16.58 9.83866 15.3824C9.97607 14.151 9.66273 12.8233 8.57655 11.5199C7.74784 10.5255 7.56125 9.60324 7.65259 8.78405C7.74768 7.93119 8.15265 7.12354 8.62437 6.4162C8.85419 6.07159 8.76113 5.60592 8.41652 5.37611C8.07191 5.14629 7.60624 5.23935 7.37642 5.58396C6.84781 6.37662 6.29536 7.42013 6.16182 8.61784C6.02453 9.84923 6.33812 11.177 7.42424 12.4802ZM16.348 15.216C16.4395 14.3968 16.253 13.4746 15.4244 12.4802C14.3382 11.177 14.0247 9.84923 14.1619 8.61784C14.2955 7.42013 14.8479 6.37662 15.3765 5.58396C15.6064 5.23935 16.072 5.14629 16.4166 5.37611C16.7612 5.60592 16.8543 6.07159 16.6245 6.4162C16.1528 7.12354 15.7478 7.93119 15.6527 8.78405C15.5614 9.60324 15.748 10.5255 16.5767 11.5199C17.6629 12.8233 17.9762 14.151 17.8388 15.3824C17.7051 16.58 17.1527 17.6235 16.6246 18.416C16.395 18.7607 15.9293 18.8539 15.5846 18.6242C15.2399 18.3945 15.1467 17.9289 15.3764 17.5842C15.8478 16.8767 16.2529 16.069 16.348 15.216ZM11.4244 12.4802C12.253 13.4746 12.4395 14.3968 12.348 15.216C12.2529 16.069 11.8478 16.8767 11.3764 17.5842C11.1467 17.9289 11.2399 18.3945 11.5846 18.6242C11.9293 18.8539 12.395 18.7607 12.6246 18.416C13.1527 17.6235 13.7051 16.58 13.8388 15.3824C13.9762 14.151 13.6629 12.8233 12.5767 11.5199C11.748 10.5255 11.5614 9.60324 11.6527 8.78405C11.7478 7.93119 12.1528 7.12354 12.6245 6.4162C12.8543 6.07159 12.7612 5.60592 12.4166 5.37611C12.072 5.14629 11.6064 5.23935 11.3765 5.58396C10.8479 6.37662 10.2955 7.42013 10.1619 8.61784C10.0247 9.84923 10.3382 11.177 11.4244 12.4802Z" fill="currentColor"/>
</svg>
''',
colorFilter:
color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
width: width,
height: height,
);