didUpdateWidget method

  1. @override
void didUpdateWidget(
  1. covariant SfCircularChart oldWidget
)
override

Called whenever the widget configuration changes.

If the parent widget rebuilds and request that this location in the tree update to display a new widget with the same runtimeType and Widget.key, the framework will update the widget property of this State object to refer to the new widget and then call this method with the previous widget as an argument.

Override this method to respond when the widget changes.

The framework always calls build after calling didUpdateWidget, which means any calls to setState in didUpdateWidget are redundant.

  • In didUpdateWidget unsubscribe from the old object and subscribe to the new one if the updated widget configuration requires replacing the object.

Here it called whenever the series collection gets updated in SfCircularChart.

Implementation

@override
void didUpdateWidget(SfCircularChart oldWidget) {
  //Update and maintain the series state, when we update the series in the series collection //
  _createAndUpdateSeriesRenderer(oldWidget);

  _needsRepaintCircularChart(_chartSeries.visibleSeriesRenderers,
      <CircularSeriesRenderer?>[_prevSeriesRenderer]);

  _needExplodeAll = widget.series.isNotEmpty &&
      widget.series[0].explodeAll &&
      widget.series[0].explode &&
      oldWidget.series[0].explodeAll != widget.series[0].explodeAll;
  _isLegendToggled = false;
  _widgetNeedUpdate = true;
  if (_legendWidgetContext.isNotEmpty) {
    _legendWidgetContext.clear();
  }
  if (_tooltipBehaviorRenderer._chartTooltipState != null) {
    _tooltipBehaviorRenderer._show = false;
  }
  super.didUpdateWidget(oldWidget);
}