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 in a number of different situations. For example:

Here it is called whenever the user interaction is performed and it removes the old widget and updates a chart with a new widget in SfCircularChart.

Implementation

@override
Widget build(BuildContext context) {
  _themeData = Theme.of(context);
  final SfChartThemeData effectiveChartThemeData = _themeData.useMaterial3
      ? SfChartThemeDataM3(context)
      : SfChartThemeDataM2(context);
  _chartThemeData = _updateThemeData(context, effectiveChartThemeData);
  final core.LegendPosition legendPosition =
      effectiveLegendPosition(widget.legend);
  final Axis orientation =
      effectiveLegendOrientation(legendPosition, widget.legend);
  Widget current = core.LegendLayout(
    key: _legendKey,
    backgroundImage: widget.backgroundImage,
    backgroundColor: widget.backgroundColor,
    padding: EdgeInsets.zero,
    showLegend: widget.legend.isVisible,
    legendPosition: legendPosition,
    legendAlignment: effectiveLegendAlignment(widget.legend.alignment),
    legendTitleAlignment:
        effectiveLegendAlignment(widget.legend.title?.alignment),
    itemIconBorderColor: widget.legend.iconBorderColor,
    itemIconBorderWidth: widget.legend.iconBorderWidth,
    legendBorderColor: widget.legend.borderColor,
    legendBackgroundColor: _chartThemeData.legendBackgroundColor,
    legendBorderWidth: widget.legend.borderWidth,
    itemOpacity: widget.legend.opacity,
    legendWidthFactor:
        percentageToWidthFactor(widget.legend.width, legendPosition),
    legendHeightFactor:
        percentageToHeightFactor(widget.legend.height, legendPosition),
    itemInnerSpacing: widget.legend.padding,
    itemSpacing: 0.0,
    itemPadding: widget.legend.itemPadding,
    itemRunSpacing: 0.0,
    itemIconHeight: widget.legend.iconHeight,
    itemIconWidth: widget.legend.iconWidth,
    scrollbarVisibility: effectiveScrollbarVisibility(widget.legend),
    enableToggling: widget.legend.toggleSeriesVisibility,
    itemTextStyle: _chartThemeData.legendTextStyle!,
    isResponsive: widget.legend.isResponsive,
    legendWrapDirection: orientation,
    legendTitle: buildLegendTitle(_chartThemeData, widget.legend),
    legendOverflowMode: effectiveOverflowMode(widget.legend),
    legendItemBuilder:
        widget.legend.legendItemBuilder != null ? _buildLegendItem : null,
    legendFloatingOffset: widget.legend.offset,
    child: ChartArea(
      legendKey: _legendKey,
      legendItems: _legendItems,
      onChartTouchInteractionDown: widget.onChartTouchInteractionDown,
      onChartTouchInteractionMove: widget.onChartTouchInteractionMove,
      onChartTouchInteractionUp: widget.onChartTouchInteractionUp,
      children: <Widget>[
        CircularChartPlotArea(
          vsync: this,
          localizations: _localizations,
          legendKey: _legendKey,
          palette: widget.palette ??
              (_themeData.useMaterial3
                  ? (effectiveChartThemeData as SfChartThemeDataM3).palette
                  : (effectiveChartThemeData as SfChartThemeDataM2).palette),
          chartThemeData: _chartThemeData,
          themeData: _themeData,
          backgroundColor: widget.backgroundColor,
          borderWidth: widget.borderWidth,
          legend: widget.legend,
          onLegendItemRender: widget.onLegendItemRender,
          onDataLabelRender: widget.onDataLabelRender,
          onLegendTapped: widget.onLegendTapped,
          onTooltipRender: widget.onTooltipRender,
          onDataLabelTapped: widget.onDataLabelTapped,
          selectionMode: SelectionType.point,
          selectionGesture: widget.selectionGesture,
          enableMultiSelection: widget.enableMultiSelection,
          tooltipBehavior: widget.tooltipBehavior,
          centerX: widget.centerX,
          centerY: widget.centerY,
          onCreateShader: widget.onCreateShader,
          onSelectionChanged: widget.onSelectionChanged,
          children: widget.series,
        ),
        if (widget.annotations != null &&
            widget.annotations!.isNotEmpty &&
            _annotations != null &&
            _annotations!.isNotEmpty)
          CircularAnnotationArea(
            annotations: widget.annotations,
            children: _annotations!,
          ),
        if (widget.tooltipBehavior != null)
          BehaviorArea(
            tooltipKey: _tooltipKey,
            chartThemeData: _chartThemeData,
            themeData: _themeData,
            tooltipBehavior: widget.tooltipBehavior,
            onTooltipRender: widget.onTooltipRender,
            children: <Widget>[
              if (widget.tooltipBehavior != null &&
                  widget.tooltipBehavior!.enable)
                CoreTooltip(
                  key: _tooltipKey,
                  builder: _buildTooltipWidget,
                  opacity: widget.tooltipBehavior!.opacity,
                  borderColor: widget.tooltipBehavior!.borderColor,
                  borderWidth: widget.tooltipBehavior!.borderWidth,
                  color: (widget.tooltipBehavior!.color ??
                      _chartThemeData.tooltipColor)!,
                  showDuration: widget.tooltipBehavior!.duration.toInt(),
                  shadowColor: widget.tooltipBehavior!.shadowColor,
                  elevation: widget.tooltipBehavior!.elevation,
                  animationDuration:
                      widget.tooltipBehavior!.animationDuration,
                  shouldAlwaysShow: widget.tooltipBehavior!.shouldAlwaysShow,
                ),
            ],
          ),
      ],
    ),
  );

  current = buildChartWithTitle(current, widget.title, _chartThemeData);

  return RepaintBoundary(
    child: Container(
      decoration: BoxDecoration(
        color: widget.backgroundColor,
        border: Border.all(
          color: widget.borderColor,
          width: widget.borderWidth,
        ),
      ),
      child: Padding(
        padding: widget.margin.resolve(Directionality.maybeOf(context)),
        child: current,
      ),
    ),
  );
}