build method

  1. @override
Widget build(
  1. BuildContext context
)
override

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:

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="M9 6C7.34315 6 6 7.34315 6 9V39C6 40.6569 7.34315 42 9 42H39C40.6569 42 42 40.6569 42 39V9C42 7.34315 40.6569 6 39 6H9ZM29.5358 10.8676C29.6039 10.4656 29.3458 10.0822 28.9593 10.0114C28.5728 9.94046 28.2042 10.2089 28.136 10.6109L27.4382 14.7264L24.8705 13.0172L23.4165 18.9996C23.3204 19.3954 23.5509 19.7973 23.9314 19.8974C24.3119 19.9974 24.6984 19.7577 24.7946 19.3619L25.7653 15.368L28.4677 17.1669L29.5358 10.8676ZM13.3939 13.1262C13.5976 12.7773 14.0347 12.6661 14.3702 12.8779L20.032 16.4519L17.2053 18.5978L20.8072 21.2641C21.127 21.5008 21.2017 21.9623 20.9742 22.2949C20.7466 22.6275 20.3028 22.7052 19.9831 22.4685L14.7745 18.6129L17.472 16.5651L13.6327 14.1416C13.2972 13.9298 13.1903 13.4752 13.3939 13.1262ZM10.3641 27.0521C10.0215 27.2513 9.89896 27.7016 10.0904 28.0579C10.2819 28.4143 10.7149 28.5417 11.0575 28.3426L14.8411 26.1435L15.2127 29.4944L20.868 26.7501C21.2236 26.5775 21.3775 26.1376 21.2115 25.7677C21.0455 25.3978 20.6227 25.2378 20.267 25.4104L16.3987 27.2875L16.0088 23.7713L10.3641 27.0521ZM19.403 37.193C19.367 37.5995 19.6547 37.9594 20.0455 37.9968C20.4364 38.0343 20.7824 37.7351 20.8184 37.3286L21.1933 33.0938L23.9265 34.5977L24.9116 28.44C24.976 28.0374 24.7143 27.6566 24.3272 27.5896C23.94 27.5226 23.5739 27.7947 23.5095 28.1974L22.8481 32.3318L19.9734 30.7501L19.403 37.193ZM37.9123 20.3784C38.101 20.7363 37.9751 21.1856 37.631 21.382L32.2191 24.4694L31.8752 21.137L28.2528 22.8587C27.8959 23.0284 27.4742 22.8649 27.3111 22.4936C27.1479 22.1223 27.3051 21.6838 27.6621 21.5141L33.078 18.9399L33.4048 22.1068L36.9474 20.0858C37.2915 19.8895 37.7235 20.0205 37.9123 20.3784ZM33.2475 34.0245C33.5831 34.2363 34.0201 34.1251 34.2238 33.7761C34.4274 33.4272 34.3205 32.9725 33.985 32.7607L30.4644 30.5384L32.9766 28.6313L28.0636 24.9944C27.7438 24.7577 27.3001 24.8355 27.0725 25.1681C26.8449 25.5006 26.9196 25.9622 27.2394 26.1989L30.5458 28.6464L27.9044 30.6517L33.2475 34.0245Z" fill="black"/>
</svg>
''',
      colorFilter:
          color != null ? widgets.ColorFilter.mode(color!, widgets.BlendMode.srcIn) : null,
      width: width,
      height: height,
    );