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="M8 11C8 10.4477 8.44771 10 9 10H17C17.5523 10 18 10.4477 18 11C18 11.5523 17.5523 12 17 12V19H20V12C19.4477 12 19 11.5523 19 11C19 10.4477 19.4477 10 20 10H28C28.5523 10 29 10.4477 29 11C29 11.5523 28.5523 12 28 12V19H31V12C30.4477 12 30 11.5523 30 11C30 10.4477 30.4477 10 31 10H39C39.5523 10 40 10.4477 40 11C40 11.5523 39.5523 12 39 12V19H41V16H43V19H44V21H43V34H44V36H43V38H41V36H7V38H5V36H4V34H5V21H4V19H5V16H7V19H9V12C8.44771 12 8 11.5523 8 11ZM7 34H41V21H39V29C39 31.2091 37.2091 33 35 33C32.7909 33 31 31.2091 31 29V21H28V29C28 31.2091 26.2091 33 24 33C21.7909 33 20 31.2091 20 29V21H17V29C17 31.2091 15.2091 33 13 33C10.7909 33 9 31.2091 9 29V21H7V34ZM15 12V19H11V12H15ZM26 19L22 19V12H26V19ZM37 19H33V12H37V19ZM11 29V21H15V29C15 30.1046 14.1046 31 13 31C11.8954 31 11 30.1046 11 29ZM22 29V21L26 21V29C26 30.1046 25.1046 31 24 31C22.8954 31 22 30.1046 22 29ZM33 29V21H37V29C37 30.1046 36.1046 31 35 31C33.8954 31 33 30.1046 33 29Z" fill="black"/>
</svg>
''',
colorFilter:
color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
width: width,
height: height,
);