setState<T extends Widget> method

void setState<T extends Widget>([
  1. VoidCallback? callback
])

Runs callback and marks a widget for rebuilding.

Rebuilds the current widget when T is omitted or is Widget. Otherwise, rebuilds the nearest ancestor whose widget is of type T.

Implementation

void setState<T extends Widget>([VoidCallback? callback]) {
  callback?.call();

  // Marks the current element for rebuilding.
  if (T == Widget) {
    (this as Element).markNeedsBuild();
    return;
  }

  // Marks the nearest ancestor of type T for rebuilding.
  visitAncestorElements((element) {
    if (element.widget is T) {
      element.markNeedsBuild();
      return false;
    }

    return true;
  });
}