setProperty method

void setProperty(
  1. String propertyName,
  2. String? value, [
  3. bool? isImportant
])

Modifies an existing CSS property or creates a new CSS property in the declaration block.

Implementation

void setProperty(String propertyName, String? value, [bool? isImportant]) {
  // Null or empty value means should be removed.
  if (isNullOrEmptyValue(value)) {
    removeProperty(propertyName, isImportant);
    return;
  }

  String normalizedValue = _toLowerCase(value.toString().trim());

  if (!_isValidValue(propertyName, normalizedValue)) return;

  if (_CSSShorthandProperty[propertyName] != null) {
    return _expandShorthand(propertyName, normalizedValue, isImportant);
  }

  // From style sheet mark the property important as false.
  if (isImportant == false) {
    _sheetStyle[propertyName] = value;
  }

  // If the important property is already set, we should ignore it.
  if (isImportant != true && _importants[propertyName] == true) {
    return;
  }

  // Current only from inline style will mark the property as important.
  if (isImportant == true) {
    _importants[propertyName] = true;
  }

  String? prevValue = getPropertyValue(propertyName);
  if (normalizedValue == prevValue) return;

  _pendingProperties[propertyName] = normalizedValue;
}