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="M17.4697 2.46967C17.7626 2.17678 18.2375 2.17678 18.5304 2.46967L22.0304 5.96967C22.2449 6.18417 22.309 6.50676 22.1929 6.78701C22.0768 7.06727 21.8034 7.25 21.5 7.25H18.75V16.5C18.75 16.9142 18.4142 17.25 18 17.25C17.5858 17.25 17.25 16.9142 17.25 16.5V7.25H14.5C14.1967 7.25 13.9232 7.06727 13.8071 6.78701C13.691 6.50676 13.7552 6.18417 13.9697 5.96967L17.4697 2.46967Z" fill="currentColor"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.25 7.5C3.25 5.15279 5.15279 3.25 7.5 3.25C9.84721 3.25 11.75 5.15279 11.75 7.5V16.5C11.75 18.0188 12.9812 19.25 14.5 19.25C16.0188 19.25 17.25 18.0188 17.25 16.5C17.25 16.0858 17.5858 15.75 18 15.75C18.4142 15.75 18.75 16.0858 18.75 16.5C18.75 18.8472 16.8472 20.75 14.5 20.75C12.1528 20.75 10.25 18.8472 10.25 16.5V7.5C10.25 5.98121 9.01879 4.75 7.5 4.75C5.98121 4.75 4.75 5.98121 4.75 7.5V19.5C4.75 19.9142 4.41421 20.25 4 20.25C3.58579 20.25 3.25 19.9142 3.25 19.5V7.5Z" fill="currentColor"/>
</svg>
''',
colorFilter:
color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
width: width,
height: height,
);