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" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M21.75 20.4C21.75 21.1456 21.1456 21.75 20.4 21.75H3.6C2.85441 21.75 2.25 21.1456 2.25 20.4V3.6C2.25 2.85441 2.85442 2.25 3.6 2.25H20.4C21.1456 2.25 21.75 2.85442 21.75 3.6V20.4ZM12.5303 11.5303L16.0303 8.03033C16.3232 7.73744 16.3232 7.26256 16.0303 6.96967C15.7374 6.67678 15.2626 6.67678 14.9697 6.96967L12 9.93934L9.03033 6.96967C8.73744 6.67678 8.26256 6.67678 7.96967 6.96967C7.67678 7.26256 7.67678 7.73744 7.96967 8.03033L11.4697 11.5303C11.7626 11.8232 12.2374 11.8232 12.5303 11.5303ZM16.0303 14.0303L12.5303 17.5303C12.2374 17.8232 11.7626 17.8232 11.4697 17.5303L7.96967 14.0303C7.67678 13.7374 7.67678 13.2626 7.96967 12.9697C8.26256 12.6768 8.73744 12.6768 9.03033 12.9697L12 15.9393L14.9697 12.9697C15.2626 12.6768 15.7374 12.6768 16.0303 12.9697C16.3232 13.2626 16.3232 13.7374 16.0303 14.0303Z" fill="currentColor"/>
</svg>
''',
colorFilter:
color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
width: width,
height: height,
);