flushPendingProperties method

void flushPendingProperties()

Implementation

void flushPendingProperties() {
  Element? _target = target;
  // If style target element not exists, no need to do flush operation.
  if (_target == null) return;

  // Display change from none to other value that the renderBoxModel is null.
  if (_pendingProperties.containsKey(DISPLAY) && _target.isConnected &&
      _target.parentElement?.renderStyle.display != CSSDisplay.sliver) {
    String? prevValue = _properties[DISPLAY];
    String currentValue = _pendingProperties[DISPLAY]!;
    _properties[DISPLAY] = currentValue;
    _pendingProperties.remove(DISPLAY);
    _emitPropertyChanged(DISPLAY, prevValue, currentValue);
  }

  // If target has no renderer attached, no need to flush.
  if (!_target.isRendererAttached) return;

  RenderBoxModel? renderBoxModel = _target.renderBoxModel;
  if (_pendingProperties.isEmpty || renderBoxModel == null) {
    return;
  }

  Map<String, String> pendingProperties = _pendingProperties;
  // Reset first avoid set property in flush stage.
  _pendingProperties = {};

  List<String> propertyNames = pendingProperties.keys.toList();
  for (String propertyName in _propertyOrders) {
    int index = propertyNames.indexOf(propertyName);
    if (index > -1) {
      propertyNames.removeAt(index);
      propertyNames.insert(0, propertyName);
    }
  }

  Map<String, String?> prevValues = {};
  for (String propertyName in propertyNames) {
    // Update the prevValue to currentValue.
    prevValues[propertyName] = _properties[propertyName];
    _properties[propertyName] = pendingProperties[propertyName]!;
  }

  for (String propertyName in propertyNames) {
    String? prevValue = prevValues[propertyName];
    String currentValue = pendingProperties[propertyName]!;

    _emitPropertyChanged(propertyName, prevValue, currentValue);
  }
}