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="M9 12V9H11V12H9Z" fill="black"/>
<path d="M13 9V12H15V9H13Z" fill="black"/>
<path d="M17 12V9H19V12H17Z" fill="black"/>
<path d="M21 9V12H23V9H21Z" fill="black"/>
<path d="M25 12V9H27V12H25Z" fill="black"/>
<path d="M29 9V12H31V9H29Z" fill="black"/>
<path d="M33 12V9H35V12H33Z" fill="black"/>
<path d="M37 9V12H39V9H37Z" fill="black"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M38.8574 15H42V9C42 7.34315 40.6569 6 39 6H9C7.34315 6 6 7.34315 6 9V15H8.14258C8.14263 15.0456 8.14423 15.0914 8.14741 15.1376L9.44827 34H9.41309L9.61715 36.4487L9.87155 40.1376C9.88309 40.3049 9.91497 40.4662 9.96469 40.6192L10.0798 42H36.9486L37.0187 40.668C37.078 40.5006 37.1157 40.3228 37.1284 40.1376L38.8526 15.1376C38.8558 15.0914 38.8573 15.0456 38.8574 15ZM40 13V9C40 8.44772 39.5523 8 39 8H9C8.44772 8 8 8.44771 8 9V13H40ZM36.4435 21L36.8573 15L10.1427 15L10.3496 18H21C22.1046 18 23 18.8954 23 20V21H36.4435ZM21.5951 35.91C22.409 35.6566 23 34.8973 23 34V23H35.9459L35.0511 40H11.92L11.6114 36.2968L11.591 36H21.5351L21.5951 35.91ZM21 20H11.1142L11.892 34H20.4647L20.9999 33.1972L21 20Z" fill="black"/>
</svg>
''',
colorFilter:
color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
width: width,
height: height,
);