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" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2 2V20C2 21.1046 2.89543 22 4 22H22V20H4V8.15637C4.91911 8.29004 6.08455 8.60683 7.01056 9.22734C7.65911 9.66192 8.20585 10.3263 8.67078 11.0359C8.89984 11.3855 9.09965 11.7311 9.27913 12.0493C9.31143 12.1066 9.34395 12.1646 9.37643 12.2225C9.51398 12.4679 9.65112 12.7125 9.76989 12.8979C10.7906 14.4918 12.7233 16 15.1792 16H18.5148L17.3816 17.3599L18.918 18.6402L21.9515 15L18.918 11.3599L17.3816 12.6402L18.5147 14H15.1792C13.5753 14 12.2095 12.9989 11.4541 11.8193C11.37 11.6881 11.2717 11.5128 11.1381 11.2748C11.1018 11.2102 11.063 11.141 11.0211 11.0668C10.8355 10.7375 10.6097 10.3459 10.3437 9.93978C9.81835 9.13802 9.09643 8.21755 8.12389 7.56586C6.79132 6.67292 5.18597 6.27915 4 6.1397V2H2Z" fill="black"/>
<path d="M18.5 4.5H21V6.5H18.5V9H16.5V6.5H14V4.5H16.5V2H18.5V4.5Z" fill="black"/>
</svg>
''',
colorFilter:
color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
width: width,
height: height,
);