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="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M31.0711 16.9289C29.6725 15.5304 27.8907 14.578 25.9509 14.1922C24.0111 13.8063 22.0004 14.0043 20.1732 14.7612C18.3459 15.5181 16.7841 16.7998 15.6853 18.4443C14.5865 20.0888 14 22.0222 14 24C14 25.9778 14.5865 27.9112 15.6853 29.5557C16.7841 31.2002 18.3459 32.4819 20.1732 33.2388C22.0004 33.9957 24.0111 34.1937 25.9509 33.8079C27.8907 33.422 29.6725 32.4696 31.0711 31.0711C31.8521 30.29 33.1184 30.29 33.8995 31.0711C34.6805 31.8521 34.6805 33.1185 33.8995 33.8995C31.9416 35.8574 29.447 37.1908 26.7313 37.731C24.0155 38.2712 21.2006 37.9939 18.6424 36.9343C16.0843 35.8747 13.8978 34.0803 12.3594 31.778C10.8211 29.4757 10 26.7689 10 24C10 21.2311 10.8211 18.5243 12.3594 16.222C13.8978 13.9197 16.0843 12.1253 18.6424 11.0657C21.2006 10.0061 24.0155 9.72882 26.7313 10.269C29.447 10.8092 31.9416 12.1426 33.8995 14.1005C34.6805 14.8816 34.6805 16.1479 33.8995 16.9289C33.1184 17.71 31.8521 17.71 31.0711 16.9289Z" fill="black"/>
</svg>
''',
colorFilter:
color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
width: width,
height: height,
);