inlineSvg function
An inline <svg> element — its attributes and the markup between its
tags — drawn as a picture.
While closed is false the element is still streaming in, and its markup
changes on every frame; parsing each version would fail and cost a parse
per frame, so only a box of its stated size shows until it is complete.
It is as wide as width says and as tall as height says. With one of
them, or none, the viewBox gives the proportions, and a drawing with
neither is 300 by 150, as in a browser. It never grows past the width it
is given. fill="currentColor" takes currentColor, so an icon follows
the text around it. Markup that does not parse, or is longer than
maxInlineSvgLength, shows error.
Parsed drawings are cached by their markup (flutter_svg's cache), so a
rebuild or a scroll draws without parsing again. Nothing is fetched: an
<image> in the drawing shows only when it is embedded as a data: URL.
Implementation
Widget inlineSvg({
required Map<String, String> attributes,
required String markup,
required bool closed,
required WidgetBuilder error,
Color? currentColor,
}) {
final size = _svgSize(attributes);
if (!closed) {
return _SvgBox(size: size, child: const SizedBox.expand());
}
if (markup.length > maxInlineSvgLength) {
return _SvgBox(
size: size,
child: Builder(builder: error),
);
}
final label = attributes['aria-label'];
return _SvgBox(
size: size,
child: SvgPicture.string(
_normalizedSvg(_svgDocument(attributes, markup)),
fit: BoxFit.contain,
theme: currentColor == null
? const SvgTheme()
: SvgTheme(currentColor: currentColor),
semanticsLabel: label,
excludeFromSemantics: label == null,
errorBuilder: (context, _, _) => error(context),
),
);
}