writeShading function

void writeShading(
  1. XmlBuilder builder, {
  2. String? fill,
  3. String? themeFill,
  4. String? themeFillTint,
  5. String? themeFillShade,
})

Writes a w:shd (shading/background) element if a fill or theme fill is set.

Shared by DocxText, DocxParagraph and DocxTableCell so background shading is serialized identically everywhere it appears, instead of each class re-implementing (and potentially forgetting part of) the same XML.

Implementation

void writeShading(
  XmlBuilder builder, {
  String? fill,
  String? themeFill,
  String? themeFillTint,
  String? themeFillShade,
}) {
  if (fill == null && themeFill == null) return;
  builder.element('w:shd', nest: () {
    builder.attribute('w:val', 'clear');
    builder.attribute('w:color', 'auto');
    builder.attribute('w:fill', fill?.replaceAll('#', '') ?? 'auto');
    if (themeFill != null) builder.attribute('w:themeFill', themeFill);
    if (themeFillTint != null) {
      builder.attribute('w:themeFillTint', themeFillTint);
    }
    if (themeFillShade != null) {
      builder.attribute('w:themeFillShade', themeFillShade);
    }
  });
}