setAttribute method

void setAttribute(
  1. String tagName,
  2. RenderBoxModel model,
  3. String name,
  4. String value,
)

Implementation

void setAttribute(
    String tagName, RenderBoxModel model, String name, String value) {
  switch (tagName) {
    case TAG_SVG:
      {
        final root = model as RenderSVGRoot;
        switch (name) {
          case 'viewBox':
            {
              root.viewBox = parseViewBox(value);
              viewBox = root.viewBox;
              return;
            }
          // width/height is always fixed as 100% to match the parent size
          // IMPROVE: width/height should support unit like px/em/rem when needed in the future
          case 'width':
            {
              width = double.tryParse(value);
              return;
            }
          case 'height':
            {
              height = double.tryParse(value);
              return;
            }
        }
      }
  }
  // TODO: support base url in attribute value like background-image
  final parsed = model.renderStyle.resolveValue(name, value);
  if (parsed != null) {
    model.renderStyle.setProperty(name, parsed);
  }
}