shouldUpdateWidget method

  1. @override
bool shouldUpdateWidget(
  1. covariant Time oldWidget
)
override

Whether to update current widget.

Framework calls this method on new widget, when new widget matches with a old widget,to check whether old widget need to update. This method should contain the logic to compare new widget with old.

Diffing process will always call shouldUpdateWidget on child widgets of current widget even if shouldUpdateWidget return false. This means whatever diffing logic is present in this method, its scope should be limited to checking just the current widget. If a widget want to short-circuit diffing process(i.e no shouldUpdateWidget on child widgets) then it can override shouldUpdateWidgetChildren method.

Implementation

@override
bool shouldUpdateWidget(covariant Time oldWidget) {
  return dateTime != oldWidget.dateTime ||
      super.shouldUpdateWidget(oldWidget);
}