scheduleBuildFor method Null safety

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 != null);
  assert(element.owner == this);
  assert(() {
    if (debugPrintScheduleBuildForStacks) {
      debugPrintStack(label: 'scheduleBuildFor() called for $element${_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.md',
        ),
      ]);
    }
    return true;
  }());
  if (element._inDirtyList) {
    assert(() {
      if (debugPrintScheduleBuildForStacks) {
        debugPrintStack(label: 'BuildOwner.scheduleBuildFor() called; _dirtyElementsNeedsResorting was $_dirtyElementsNeedsResorting (now true); dirty list is: $_dirtyElements');
      }
      if (!_debugIsInBuildScope) {
        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;
    }());
    _dirtyElementsNeedsResorting = true;
    return;
  }
  if (!_scheduledFlushDirtyElements && onBuildScheduled != null) {
    _scheduledFlushDirtyElements = true;
    onBuildScheduled!();
  }
  _dirtyElements.add(element);
  element._inDirtyList = true;
  assert(() {
    if (debugPrintScheduleBuildForStacks) {
      debugPrint('...dirty list is now: $_dirtyElements');
    }
    return true;
  }());
}