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="M9 6C7.34315 6 6 7.34315 6 9V39C6 40.6569 7.34315 42 9 42H39C40.6569 42 42 40.6569 42 39V9C42 7.34315 40.6569 6 39 6H9ZM20 25C20 24.5918 19.7519 24.2246 19.3732 24.0723C18.9946 23.9199 18.5613 24.013 18.2786 24.3075L16.2786 26.3908C15.8961 26.7892 15.9091 27.4222 16.3075 27.8047C16.7059 28.1872 17.3389 28.1743 17.7214 27.7759L18 27.4856V35C18 35.5523 18.4477 36 19 36C19.5523 36 20 35.5523 20 35V25ZM26.625 26C25.681 26 25 26.717 25 27.5V31.7926L28.6877 26.0277C28.5869 26.0095 28.4824 26 28.375 26H26.625ZM30 27.6877L26.0287 33.8959C26.2121 33.9628 26.4129 34 26.625 34H28.375C29.319 34 30 33.283 30 32.5V27.6877ZM23 27.5C23 25.5216 24.6695 24 26.625 24H28.375C29.2886 24 30.1311 24.3277 30.7737 24.8755C31.5168 25.509 32 26.4453 32 27.5V32.5C32 34.4784 30.3305 36 28.375 36H26.625C25.5684 36 24.6072 35.5618 23.9397 34.8515C23.361 34.2357 23 33.4107 23 32.5V27.5ZM13 12C12.4477 12 12 12.4477 12 13C12 13.5523 12.4477 14 13 14H14V18H13C12.4477 18 12 18.4477 12 19C12 19.5523 12.4477 20 13 20H17C17.5523 20 18 19.5523 18 19C18 18.4477 17.5523 18 17 18H16V14H17C17.5523 14 18 13.5523 18 13C18 12.4477 17.5523 12 17 12H13ZM25.8557 14.3698C25.548 14.0621 25.156 13.8525 24.7292 13.7677C24.3025 13.6828 23.8601 13.7263 23.4581 13.8929C23.0561 14.0594 22.7126 14.3413 22.4708 14.7031C22.2291 15.0649 22.1 15.4903 22.1 15.9254C22.1 16.3605 22.2291 16.7859 22.4708 17.1476C22.7126 17.5094 23.0561 17.7914 23.4581 17.9579C23.8601 18.1244 24.3025 18.168 24.7292 18.0831C25.156 17.9982 25.548 17.7887 25.8557 17.481C26.2462 17.0905 26.8794 17.0905 27.2699 17.481C27.6604 17.8715 27.6604 18.5047 27.2699 18.8952C26.6825 19.4826 25.9341 19.8826 25.1194 20.0447C24.3047 20.2067 23.4602 20.1236 22.6928 19.8057C21.9253 19.4878 21.2694 18.9495 20.8079 18.2588C20.3464 17.5681 20.1 16.7561 20.1 15.9254C20.1 15.0947 20.3464 14.2827 20.8079 13.592C21.2694 12.9013 21.9253 12.363 22.6928 12.0451C23.4602 11.7272 24.3047 11.644 25.1194 11.8061C25.9341 11.9681 26.6825 12.3682 27.2699 12.9555C27.6604 13.3461 27.6604 13.9792 27.2699 14.3698C26.8794 14.7603 26.2462 14.7603 25.8557 14.3698ZM31 12C30.4477 12 30 12.4477 30 13V19C30 19.5523 30.4477 20 31 20H33C35.2091 20 37 18.2091 37 16C37 13.7909 35.2091 12 33 12H31ZM32 18V14H33C34.1046 14 35 14.8954 35 16C35 17.1046 34.1046 18 33 18H32Z" fill="black"/>
</svg>
''',
colorFilter:
color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
width: width,
height: height,
);