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="M24 16C26.7625 16 29 13.7625 29 11C29 8.2375 26.7625 6 24 6C21.2375 6 19 8.2375 19 11C19 13.7625 21.2375 16 24 16Z" fill="black"/>
<path d="M15 21C15 18.5173 20.9963 17 24 17C27.0037 17 33 18.5173 33 21V24H15V21Z" fill="black"/>
<path d="M20 38C20 36.1362 21.2748 34.5701 23 34.126V31.7647H11V34.126C12.7252 34.5701 14 36.1362 14 38C14 40.2091 12.2091 42 10 42C7.79086 42 6 40.2091 6 38C6 36.1362 7.27477 34.5701 9 34.126V31.7647C9 30.6601 9.89543 29.7647 11 29.7647L23 29.7647V26H25V29.7647L37 29.7647C38.1046 29.7647 39 30.6601 39 31.7647V34.126C40.7252 34.5701 42 36.1362 42 38C42 40.2091 40.2091 42 38 42C35.7909 42 34 40.2091 34 38C34 36.1362 35.2748 34.5701 37 34.126V31.7647H25V34.126C26.7252 34.5701 28 36.1362 28 38C28 40.2091 26.2091 42 24 42C21.7909 42 20 40.2091 20 38Z" fill="black"/>
</svg>
''',
colorFilter:
color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
width: width,
height: height,
);