shouldUpdateWidget method

  1. @override
bool shouldUpdateWidget(
  1. Widget 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(oldWidget) {
  oldWidget as HTMLWidgetBase;

  return id != oldWidget.id ||
      title != oldWidget.title ||
      style != oldWidget.style ||
      className != oldWidget.className ||
      hidden != oldWidget.hidden ||
      innerText != oldWidget.innerText ||
      !fnIsKeyValueMapEqual(
        additionalAttributes,
        oldWidget.additionalAttributes,
      );
}