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="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M13.4149 1.97392C12.544 1.4514 11.4561 1.4514 10.5852 1.9739L2.58513 6.77392C1.75683 7.27091 1.25 8.16605 1.25 9.13203V19.9996C1.25 21.5185 2.48122 22.7496 4 22.7496H20C21.5188 22.7496 22.75 21.5185 22.75 19.9996V9.13203C22.75 8.16605 22.2432 7.27091 21.4149 6.77393L13.4149 1.97392ZM7.4301 11.3856C7.09076 11.148 6.62311 11.2306 6.38558 11.5699C6.14804 11.9092 6.23057 12.3769 6.5699 12.6144L11.5699 16.1144C11.8281 16.2952 12.1719 16.2952 12.4301 16.1144L17.4301 12.6144C17.7694 12.3769 17.852 11.9092 17.6144 11.5699C17.3769 11.2306 16.9092 11.148 16.5699 11.3856L12 14.5845L7.4301 11.3856Z" fill="currentColor"/>
</svg>
''',
colorFilter:
color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
width: width,
height: height,
);