performRebuild method

  1. @override
void performRebuild()
override

Calls the StatelessWidget.build method of the StatelessWidget object (for stateless widgets) or the State.build method of the State object (for stateful widgets) and then updates the widget tree.

Called automatically during mount to generate the first build, and by rebuild when the element needs updating.

Implementation

@override
@pragma('vm:notify-debugger-on-exception')
void performRebuild() {
  Widget? built;
  try {
    assert(() {
      _debugDoingBuild = true;
      return true;
    }());
    built = build();
    assert(() {
      _debugDoingBuild = false;
      return true;
    }());
    debugWidgetBuilderValue(widget, built);
  } catch (e, stack) {
    _debugDoingBuild = false;
    built = ErrorWidget.builder(
      _reportException(
        ErrorDescription('building $this'),
        e,
        stack,
        informationCollector: () => <DiagnosticsNode>[
          if (kDebugMode)
            DiagnosticsDebugCreator(DebugCreator(this)),
        ],
      ),
    );
  } finally {
    // We delay marking the element as clean until after calling build() so
    // that attempts to markNeedsBuild() during build() will be ignored.
    super.performRebuild(); // clears the "dirty" flag
  }
  try {
    _child = updateChild(_child, built, slot);
    assert(_child != null);
  } catch (e, stack) {
    built = ErrorWidget.builder(
      _reportException(
        ErrorDescription('building $this'),
        e,
        stack,
        informationCollector: () => <DiagnosticsNode>[
          if (kDebugMode)
            DiagnosticsDebugCreator(DebugCreator(this)),
        ],
      ),
    );
    _child = updateChild(null, built, slot);
  }
}