scheduleBuildFor method

void scheduleBuildFor(
  1. Element element
)

Adds an element to the dirty elements list so that it will be rebuilt when WidgetsBinding.drawFrame calls buildScope.

Implementation

void scheduleBuildFor(Element element) {
  assert(element.owner == this);
  assert(element._parentBuildScope != null);
  assert(() {
    if (debugPrintScheduleBuildForStacks) {
      debugPrintStack(label: 'scheduleBuildFor() called for $element${element.buildScope._dirtyElements.contains(element) ? " (ALREADY IN LIST)" : ""}');
    }
    if (!element.dirty) {
      throw FlutterError.fromParts(<DiagnosticsNode>[
        ErrorSummary('scheduleBuildFor() called for a widget that is not marked as dirty.'),
        element.describeElement('The method was called for the following element'),
        ErrorDescription(
          'This element is not current marked as dirty. Make sure to set the dirty flag before '
          'calling scheduleBuildFor().',
        ),
        ErrorHint(
          'If you did not attempt to call scheduleBuildFor() yourself, then this probably '
          'indicates a bug in the widgets framework. Please report it:\n'
          '  https://github.com/flutter/flutter/issues/new?template=2_bug.yml',
        ),
      ]);
    }
    return true;
  }());
  final BuildScope buildScope = element.buildScope;
  assert(() {
    if (debugPrintScheduleBuildForStacks && element._inDirtyList) {
      debugPrintStack(
        label: 'BuildOwner.scheduleBuildFor() called; '
                '_dirtyElementsNeedsResorting was ${buildScope._dirtyElementsNeedsResorting} (now true); '
                'The dirty list for the current build scope is: ${buildScope._dirtyElements}',
      );
    }
    // When reactivating an inactivate Element, _scheduleBuildFor should only be
    // called within _flushDirtyElements.
    if (!_debugBuilding && element._inDirtyList) {
      throw FlutterError.fromParts(<DiagnosticsNode>[
        ErrorSummary('BuildOwner.scheduleBuildFor() called inappropriately.'),
        ErrorHint(
          'The BuildOwner.scheduleBuildFor() method should only be called while the '
          'buildScope() method is actively rebuilding the widget tree.',
        ),
      ]);
    }
    return true;
  }());
  if (!_scheduledFlushDirtyElements && onBuildScheduled != null) {
    _scheduledFlushDirtyElements = true;
    onBuildScheduled!();
  }
  buildScope._scheduleBuildFor(element);
  assert(() {
    if (debugPrintScheduleBuildForStacks) {
      debugPrint("...the build scope's dirty list is now: $buildScope._dirtyElements");
    }
    return true;
  }());
}