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="M8 9V35C8 36.6569 9.34315 38 11 38H22.8321C22.2969 36.7751 22 35.4222 22 34C22 28.4772 26.4772 24 32 24C32.6849 24 33.3538 24.0689 34 24.2V9C34 7.34315 32.6569 6 31 6H11C9.34315 6 8 7.34315 8 9ZM13 13C12.4477 13 12 13.4477 12 14C12 14.5523 12.4477 15 13 15H29C29.5523 15 30 14.5523 30 14C30 13.4477 29.5523 13 29 13H13ZM13 18C12.4477 18 12 18.4477 12 19C12 19.5523 12.4477 20 13 20H29C29.5523 20 30 19.5523 30 19C30 18.4477 29.5523 18 29 18H13ZM12 24C12 23.4477 12.4477 23 13 23H21C21.5523 23 22 23.4477 22 24C22 24.5523 21.5523 25 21 25H13C12.4477 25 12 24.5523 12 24ZM13 28C12.4477 28 12 28.4477 12 29C12 29.5523 12.4477 30 13 30H18C18.5523 30 19 29.5523 19 29C19 28.4477 18.5523 28 18 28H13Z" fill="black"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M32 42C36.4183 42 40 38.4183 40 34C40 29.5817 36.4183 26 32 26C27.5817 26 24 29.5817 24 34C24 38.4183 27.5817 42 32 42ZM34.567 30.2929C34.9575 29.9024 35.5906 29.9024 35.9812 30.2929C36.3717 30.6834 36.3717 31.3166 35.9812 31.7071L35.1902 32.498L33.776 31.0838L34.567 30.2929ZM28 36.8597L33.0689 31.7909L34.4831 33.2052L29.4143 38.274H28.0001L28 36.8597Z" fill="black"/>
</svg>
''',
colorFilter:
color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
width: width,
height: height,
);