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="M12 3C10.0222 3 8.08879 3.58649 6.4443 4.6853C5.89702 5.05099 5.3899 5.46796 4.92893 5.92893C4.00483 6.85305 3.2662 7.95402 2.76121 9.17317C2.25624 10.3923 2.00003 11.693 2 12.9999C1.99999 13.6518 2.06373 14.3053 2.19215 14.9509C2.578 16.8907 3.53041 18.6725 4.92894 20.0711L5.63604 20.7782L8.05723 18.357L6.64302 16.9428L5.68041 17.9054C4.92155 16.9277 4.39694 15.7835 4.15372 14.5607C4.11667 14.3745 4.08636 14.1874 4.06273 13.9999L5.99967 14L6.00033 12L4.06276 11.9999C4.15155 11.2952 4.33424 10.6018 4.60897 9.93853C4.88371 9.27525 5.24489 8.6557 5.68041 8.09462L6.29289 8.7071L6.79289 9.20711L8.20711 7.79289L7.09462 6.6804C7.2439 6.56453 7.39758 6.45372 7.55544 6.34824C8.59203 5.65562 9.77211 5.21744 11 5.06274L11 6.5L13 6.5L13 5.06274C14.2279 5.21744 15.408 5.65561 16.4446 6.34824C16.6024 6.45372 16.7561 6.56453 16.9054 6.6804L15.7929 7.79289L17.2071 9.20711L18.3196 8.09462C18.7551 8.6557 19.1163 9.27525 19.391 9.93853C19.6658 10.6018 19.8485 11.2953 19.9373 11.9999L18 12V14L19.9373 13.9999C19.9136 14.1874 19.8833 14.3745 19.8463 14.5607C19.6031 15.7835 19.0785 16.9277 18.3196 17.9054L17.357 16.9428L15.9428 18.357L18.364 20.7782L19.0711 20.0711C20.4696 18.6725 21.422 16.8907 21.8079 14.9509C21.9363 14.3053 22 13.6518 22 12.9999C22 11.693 21.7438 10.3923 21.2388 9.17317C20.7338 7.95402 19.9952 6.85305 19.0711 5.92893C18.6101 5.46796 18.103 5.05099 17.5557 4.6853C15.9112 3.58649 13.9778 3 12 3Z" fill="black"/>
<path d="M13 13V8.5C13 7.94772 12.5523 7.5 12 7.5C11.4477 7.5 11 7.94772 11 8.5V13C11 13.5523 11.4477 14 12 14C12.5523 14 13 13.5523 13 13Z" fill="black"/>
</svg>
''',
colorFilter:
color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
width: width,
height: height,
);