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="M24 12C25.6569 12 27 10.6569 27 9C27 7.34315 25.6569 6 24 6C22.3431 6 21 7.34315 21 9C21 10.6569 22.3431 12 24 12ZM24 14C26.7614 14 29 11.7614 29 9C29 6.23858 26.7614 4 24 4C21.2386 4 19 6.23858 19 9C19 11.7614 21.2386 14 24 14Z" fill="black"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M17.374 18.3144C18.3174 18.494 19 19.3188 19 20.2792L19 41C19 41.5523 19.4477 42 20 42H20.0868C20.604 42 21.0359 41.6056 21.0827 41.0905L22 31C22.0029 29.8975 22.8975 29.0052 24 29.0052C25.1025 29.0052 25.9971 29.8974 26 30.9999L26.9173 41.0905C26.9641 41.6056 27.396 42 27.9132 42H28C28.5523 42 29 41.5523 29 41V20.3169C29 19.3564 29.6828 18.5316 30.6264 18.3521C32.3824 18.0182 34.2392 17.5548 36.2798 16.9601C36.8101 16.8056 37.1146 16.2505 36.9601 15.7202C36.8056 15.19 36.2505 14.8855 35.7202 15.04C31.0861 16.3906 27.5307 17.0156 24.0043 16.9998C20.4743 16.9839 16.9146 16.3259 12.2674 15.0365C11.7352 14.8888 11.1841 15.2005 11.0364 15.7327C10.8888 16.2649 11.2005 16.816 11.7327 16.9636C13.7658 17.5278 15.6186 17.9803 17.374 18.3144ZM22.9779 41.8025C22.6245 43.0798 21.4552 44 20.0868 44H20C18.3431 44 17 42.6569 17 41L17 20.2792C15.1742 19.9317 13.2653 19.4645 11.1979 18.8908C9.60138 18.4478 8.66625 16.7945 9.10925 15.1979C9.55225 13.6014 11.2056 12.6663 12.8021 13.1093C17.3715 14.3772 20.7371 14.9851 24.0132 14.9998C27.2788 15.0144 30.6314 14.4399 35.1606 13.1199C36.7513 12.6563 38.4166 13.57 38.8802 15.1606C39.3438 16.7513 38.4301 18.4166 36.8394 18.8802C34.7552 19.4876 32.8345 19.9681 31 20.3169V41C31 42.6569 29.6569 44 28 44H27.9132C26.5448 44 25.3755 43.0798 25.0221 41.8025C24.9897 41.6851 24.9641 41.5647 24.9458 41.4417C24.9375 41.3856 24.9307 41.3288 24.9255 41.2716L24.0082 31.1811C24.0029 31.1223 24.0002 31.0637 24 31.0052C23.9998 31.0637 23.9971 31.1223 23.9918 31.1811L23.0745 41.2716C23.0693 41.3288 23.0625 41.3856 23.0542 41.4417C23.0359 41.5647 23.0103 41.6851 22.9779 41.8025Z" fill="black"/>
</svg>
''',
colorFilter:
color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
width: width,
height: height,
);