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 6C21.7909 6 20 7.79086 20 10C20 12.2091 21.7909 14 24 14C26.2091 14 28 12.2091 28 10C28 7.79086 26.2091 6 24 6ZM18 10C18 6.68629 20.6863 4 24 4C27.3137 4 30 6.68629 30 10C30 13.3137 27.3137 16 24 16C20.6863 16 18 13.3137 18 10ZM15.3077 19.4615C15.9288 17.971 17.3852 17 19 17H29C30.6148 17 32.0712 17.971 32.6923 19.4615L35.1923 25.4615C36.2247 27.9393 34.5742 30.6549 32 30.9697V31.8915C32 32.2363 32.1776 32.5568 32.47 32.7395L38.018 36.207C39.251 36.9776 40 38.329 40 39.783C40 42.112 38.112 44 35.783 44H12.2132C9.88632 44 8 42.1137 8 39.7868C8 38.3299 8.75264 36.9764 9.99021 36.2078L15.5776 32.7373C15.8714 32.5549 16.05 32.2336 16.05 31.8878V30.9755C13.4472 30.69 11.7686 27.9553 12.8077 25.4615L15.3077 19.4615ZM18.05 31V31.8878C18.05 32.9252 17.5141 33.8889 16.6329 34.4363L11.0455 37.9067C10.3954 38.3105 10 39.0215 10 39.7868C10 41.0091 10.9909 42 12.2132 42H30C30.5523 42 31 41.5523 31 41V40.8707C31 40.3443 30.5919 39.9081 30.0667 39.8729L16.9833 38.9978C16.4322 38.9609 16.0154 38.4843 16.0522 37.9333C16.0891 37.3822 16.5657 36.9654 17.1167 37.0022L30.2002 37.8774C31.7758 37.9828 33 39.2916 33 40.8707V41C33 41.3506 32.9398 41.6872 32.8293 42H35.783C37.0074 42 38 41.0074 38 39.783C38 39.0186 37.6062 38.3081 36.958 37.903L31.41 34.4355C30.5329 33.8873 30 32.9259 30 31.8915V31H27.2426C26.1818 31 25.1644 30.5786 24.4142 29.8284L24 29.4142L23.5858 29.8284C22.8356 30.5786 21.8182 31 20.7574 31H18.05ZM25 27.5858L25.8284 28.4142C26.2035 28.7893 26.7122 29 27.2426 29H31.5C32.9272 29 33.8951 27.5481 33.3462 26.2308L30.8462 20.2308C30.5356 19.4855 29.8074 19 29 19H19C18.1926 19 17.4644 19.4855 17.1538 20.2308L14.6538 26.2308C14.1049 27.5481 15.0728 29 16.5 29H20.7574C21.2878 29 21.7965 28.7893 22.1716 28.4142L23 27.5858V25.2662C22.7743 25.3964 22.5692 25.5743 22.4 25.8L21.8 26.6C21.6111 26.8518 21.3148 27 21 27H18C17.6534 27 17.3316 26.8205 17.1493 26.5257C16.9671 26.2309 16.9506 25.8628 17.1056 25.5528L18.1056 23.5528C18.3526 23.0588 18.9532 22.8586 19.4472 23.1056C19.9412 23.3526 20.1414 23.9532 19.8944 24.4472L19.618 25H20.5L20.8 24.6C22.4 22.4667 25.6 22.4667 27.2 24.6L27.5 25H28.382L28.1056 24.4472C27.8586 23.9532 28.0588 23.3526 28.5528 23.1056C29.0468 22.8586 29.6474 23.0588 29.8944 23.5528L30.8944 25.5528C31.0494 25.8628 31.0329 26.2309 30.8507 26.5257C30.6684 26.8205 30.3466 27 30 27H27C26.6852 27 26.3889 26.8518 26.2 26.6L25.6 25.8C25.4308 25.5743 25.2257 25.3964 25 25.2662V27.5858Z" fill="black"/>
</svg>
''',
colorFilter:
color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
width: width,
height: height,
);