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 d="M21.2628 7.45335L19.7725 8.30133L18.5536 6.11377L15.9236 7.55774L17.1648 9.78518L15.6565 10.6434L16.7178 12.4816C15.9661 13.4147 15.825 14.7493 16.465 15.8498L17.0605 16.8737C14.3072 18.4587 12.1866 20.3519 11.0013 22.7054C9.85852 24.9745 9.64219 27.5564 10.4036 30.4838C8.31701 32.3165 7 35.0043 7 37.9997C7 39.422 7.2969 40.7748 7.83209 41.9997H40C40.5523 41.9997 41 41.552 41 40.9997C41 40.4475 40.5523 39.9997 40 39.9997H26.8C26.9311 39.3535 27 38.6847 27 37.9997C27 36.4632 26.6535 35.0076 26.0343 33.7069L38.0764 26.9207L37.0836 25.1845L25.0036 31.992L25.9963 33.7281L19.4822 37.3991L18.4895 35.6629L24.9975 31.9954C23.1728 29.569 20.2697 27.9997 17 27.9997C15.2478 27.9997 13.6009 28.4504 12.1688 29.2421C11.7274 27.0309 11.9897 25.1892 12.7876 23.605C13.7356 21.7227 15.503 20.0767 18.0659 18.6026L20.9877 23.6267C21.8206 25.0589 23.6611 25.5521 25.0986 24.7282L25.7658 24.3458L26.3749 25.5231L29.0488 24.1607L28.3717 22.8521L29.2202 22.3658C30.6576 21.5419 31.1477 19.7129 30.3148 18.2806L25.7921 10.5037C25.0646 9.25274 23.5684 8.71818 22.2435 9.15192L21.2628 7.45335Z" fill="black"/>
</svg>
''',
colorFilter:
color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
width: width,
height: height,
);