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="M3.6 2.25C2.85442 2.25 2.25 2.85441 2.25 3.6V20.4C2.25 21.1456 2.85441 21.75 3.6 21.75H20.4C21.1456 21.75 21.75 21.1456 21.75 20.4V3.6C21.75 2.85442 21.1456 2.25 20.4 2.25H3.6ZM12 7.25C10.2082 7.25 9.10255 7.8072 8.50884 8.71426C8.15806 9.25017 8.03854 9.84183 7.99795 10.3226C7.55315 10.4081 7.05884 10.5775 6.6096 10.874C5.84931 11.3758 5.25 12.2269 5.25 13.5C5.25 14.7731 5.84931 15.6242 6.6096 16.126C7.3295 16.6011 8.16513 16.75 8.72727 16.75H15.2727C15.8349 16.75 16.6705 16.6011 17.3904 16.126C18.1507 15.6242 18.75 14.7731 18.75 13.5C18.75 12.2269 18.1507 11.3758 17.3904 10.874C16.9412 10.5775 16.4468 10.4081 16.0021 10.3226C15.9615 9.84183 15.8419 9.25017 15.4912 8.71426C14.8975 7.8072 13.7918 7.25 12 7.25Z" fill="currentColor"/>
</svg>
''',
colorFilter:
color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
width: width,
height: height,
);