build method
Describes the part of the user interface represented by this widget.
The framework calls this method in a number of different situations. For example:
- After calling initState.
- After calling didUpdateWidget.
- After receiving a call to setState.
- After a dependency of this State object changes.
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 SfPyramidChart.
Implementation
@override
Widget build(BuildContext context) {
_themeData = Theme.of(context);
final ChartThemeData effectiveChartThemeData = ChartThemeData(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,
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(
legendItems: _legendItems,
legendKey: _legendKey,
onChartTouchInteractionDown: widget.onChartTouchInteractionDown,
onChartTouchInteractionMove: widget.onChartTouchInteractionMove,
onChartTouchInteractionUp: widget.onChartTouchInteractionUp,
children: <Widget>[
ChartPlotArea(
vsync: this,
localizations: _localizations,
legendKey: _legendKey,
backgroundColor: null,
borderWidth: widget.borderWidth,
legend: widget.legend,
onLegendItemRender: widget.onLegendItemRender,
onDataLabelRender: widget.onDataLabelRender,
onLegendTapped: widget.onLegendTapped,
onTooltipRender: widget.onTooltipRender,
onDataLabelTapped: widget.onDataLabelTapped,
palette: widget.palette ?? effectiveChartThemeData.palette,
selectionMode: SelectionType.point,
selectionGesture: widget.selectionGesture,
enableMultiSelection: widget.enableMultiSelection,
tooltipBehavior: widget.tooltipBehavior,
onSelectionChanged: widget.onSelectionChanged,
chartThemeData: _chartThemeData,
themeData: _themeData,
children: <Widget>[widget.series],
),
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(
image: widget.backgroundImage != null
? DecorationImage(
image: widget.backgroundImage!,
fit: BoxFit.fill,
)
: null,
color: _chartThemeData.backgroundColor,
border: Border.all(
color: widget.borderColor,
width: widget.borderWidth,
),
),
child: Padding(
padding: widget.margin.resolve(Directionality.maybeOf(context)),
child: current,
),
),
);
}