putStyleProperty method

void putStyleProperty(
  1. String stylePropertyKey,
  2. String value
)

Implementation

void putStyleProperty(String stylePropertyKey, String value) {
  // update the raw tag with as little changes as possible

  // create a style="" if not already present
  RegExp styleExpressionQuery = RegExp(r'style=".*"');
  if (!styleExpressionQuery.hasMatch(rawTag)) {
    rawTag = rawTag.substring(0, rawTag.length - 1) + " style=\"\">";
  }

  // if the style property is there, cut it
  var match = styleExpressionQuery.firstMatch(rawTag)!;
  if (styleProperties.containsKey(stylePropertyKey)) {
    var stylePropertyQuery =
        RegExp("$stylePropertyKey:.*[;\"]").firstMatch(rawTag)!;

    rawTag = rawTag.substring(0, stylePropertyQuery.start) +
        rawTag.substring(stylePropertyQuery.end - 1);
  }

  // account for style="
  var start = match.start + 7;
  rawTag = rawTag.substring(0, start) +
      "$stylePropertyKey:$value;" +
      rawTag.substring(start);

  styleProperties[stylePropertyKey] = value;
}