markNeedsBuild method

void markNeedsBuild()

Rebuilds the selection toolbar or handles if they are present.

Implementation

void markNeedsBuild() {
  if (_handles == null && _toolbar == null) {
    return;
  }
  // If we are in build state, it will be too late to update visibility.
  // We will need to schedule the build in next frame.
  if (SchedulerBinding.instance.schedulerPhase == SchedulerPhase.persistentCallbacks) {
    if (_buildScheduled) {
      return;
    }
    _buildScheduled = true;
    SchedulerBinding.instance.addPostFrameCallback((Duration duration) {
      _buildScheduled = false;
      if (_handles != null) {
        _handles!.start.markNeedsBuild();
        _handles!.end.markNeedsBuild();
      }
      _toolbar?.markNeedsBuild();
      if (_contextMenuController.isShown) {
        _contextMenuController.markNeedsBuild();
      } else if (_spellCheckToolbarController.isShown) {
        _spellCheckToolbarController.markNeedsBuild();
      }
    }, debugLabel: 'SelectionOverlay.markNeedsBuild');
  } else {
    if (_handles != null) {
      _handles!.start.markNeedsBuild();
      _handles!.end.markNeedsBuild();
    }
    _toolbar?.markNeedsBuild();
    if (_contextMenuController.isShown) {
      _contextMenuController.markNeedsBuild();
    } else if (_spellCheckToolbarController.isShown) {
      _spellCheckToolbarController.markNeedsBuild();
    }
  }
}