SvgDrawing class
A parsed, dependency-free rendering of a small SVG subset.
Supported subset
- Structure:
<svg>(viewBox,width/height),<g>,<defs>,<clipPath>,<use>-free. - Shapes:
<path>,<rect>(includingrx/ry),<circle>,<ellipse>,<polygon>. - Paint:
fill(#rgb,#rgba,#rrggbb,#rrggbbaa,rgb(),rgba(), a handful of named colors,none),fill-opacity,fill-rule,opacity, and the same properties written inside astyle="…"attribute. - Geometry:
transform(matrix,translate,scale,rotate,skewX,skewY) andclip-path="url(#id)".
Everything else — strokes, gradients, filters, text, images, masks,
objectBoundingBox clip units — is ignored by design. Group opacity is
multiplied into descendant fills rather than composited through a layer,
which is exact for non-overlapping flat artwork.
This exists so package:device_preview can draw device bodies with zero
dependencies; it is not a general purpose SVG renderer.
- Annotations
Constructors
-
SvgDrawing({required Rect viewBox, required List<
SvgShape> shapes}) -
Creates a drawing from already-flattened
shapes.const - SvgDrawing.parse(String source)
-
Parses an SVG document.
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isEmpty → bool
-
Whether this drawing paints nothing.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
shapes
→ List<
SvgShape> -
The flattened shapes, in paint order.
final
- size → Size
-
The size of viewBox.
no setter
- viewBox → Rect
-
The document's coordinate space.
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
paint(
Canvas canvas, {Color? currentColor}) → void - Paints the drawing in its own view box coordinates.
-
paintInto(
Canvas canvas, Rect destination, {Color? currentColor}) → void -
Paints the drawing stretched onto
destination. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- empty → const SvgDrawing
- An empty drawing that paints nothing.