# SVG to Flutter converter: CustomPainter and Path code from any SVG

> Paste an SVG and get Flutter CustomPainter or Path code, with arcs, transforms and colors converted, plus a draw-on animation preview. Runs in your browser.

- Author: [Ivan Chernoknizhnikov](https://treamz.me/)
- Updated: 2026-11-18
- Interactive version: https://treamz.me/tools/svg-to-flutter (runs in the browser; nothing entered is sent anywhere)
- Language: en

Paste an SVG icon and get Flutter code that draws it without any package: a `CustomPainter` that builds each shape as a `Path` with `moveTo`, `lineTo`, `cubicTo`, `quadraticBezierTo` and `close`, and paints it with the SVG's own fills and strokes. You also get a draw-on (line drawing) animation of the same artwork, previewed here and ready to drop into a Flutter app. The SVG is read by your browser and never uploaded.

## What gets converted, and into what

The converter reads the markup with the browser's XML parser, then parses path data and shapes itself. Every coordinate ends up absolute, with all `transform` attributes (including nested groups) already applied, so the Dart code needs no matrices. The painter scales the viewBox into the canvas the way an SVG does by default: centered, keeping its aspect ratio.

| SVG | Flutter |
| --- | --- |
| `M` / `m` | `moveTo` |
| `L`, `H`, `V` (and lower case) | `lineTo` |
| `C`, `S` | `cubicTo`, with the reflected control point for `S` |
| `Q`, `T` | `quadraticBezierTo`, reflected for `T` |
| `A` / `a` (elliptical arc) | one `cubicTo` per quarter turn or less |
| `Z` / `z` | `close` |
| `rect` (with `rx`/`ry`), `circle`, `ellipse`, `line`, `polyline`, `polygon` | the same path commands |
| `fill-rule="evenodd"` | `PathFillType.evenOdd` |
| `fill`, `stroke`, `opacity`, `fill-opacity`, `stroke-opacity` | `Paint().color` as `Color(0xAARRGGBB)` |
| `stroke-width`, `stroke-linecap`, `stroke-linejoin`, `stroke-miterlimit` | `strokeWidth`, `StrokeCap`, `StrokeJoin`, `strokeMiterLimit` |

Styles are resolved the way SVG inherits them: presentation attributes, the `style` attribute on top, and values passed down from parent groups. Colors can be hex, `rgb()`, `hsl()`, named colors or `currentColor`. For a small icon the output looks like this, here for a circle with a 1.5-unit stroke:

```
final path1 = Path()
  ..moveTo(23, 12)
  ..cubicTo(23, 18.08, 18.08, 23, 12, 23)
  ..cubicTo(5.92, 23, 1, 18.08, 1, 12)
  ..cubicTo(1, 5.92, 5.92, 1, 12, 1)
  ..cubicTo(18.08, 1, 23, 5.92, 23, 12)
  ..close();
canvas.drawPath(
  path1,
  Paint()
    ..style = PaintingStyle.stroke
    ..strokeWidth = 1.5
    ..color = const Color(0xFF2E7D32),
);
```

## Why arcs become cubic Béziers

Flutter's `Path` has `arcToPoint`, but once a group's rotation, scale or skew is baked into the coordinates, an arc's radii and angle change with it. Cubics survive any affine transform exactly: transform the four points and you have the transformed curve. So each arc is converted with the method in the SVG specification's implementation notes: find the center from the endpoints and the two flags, scale the radii up if they are too small to reach the end point, then cover the sweep in pieces of at most 90°. A quarter circle drawn this way is off by under 0.03% of its radius, far below a pixel at icon sizes.

## CustomPainter or flutter_svg?

If you have many SVG assets, or they change often, keep them as files and draw them with the flutter_svg package. Converting to a `CustomPainter` is worth it when you want one icon with no dependency and no asset loading, when you need the `Path` itself (for clipping, hit testing, a custom `ShapeBorder` or `computeMetrics()`), or when you want to change colors and stroke widths from code. Pick “Path builder function only” for the second case: it returns every shape as one `Path` in viewBox units, without paint.

## Animating it as a line drawing

The second code block is the same artwork as an animated SVG. Each shape's stroke grows along the path, one after another, and the fills can fade in at the end; shapes with no stroke of their own get a thin outline in their fill color. The animated SVG is played in Flutter by svg_animate, my open-source package for SVGs that carry their own SMIL or CSS animation. The usual trick of animating `stroke-dashoffset` doesn't survive its renderer, which drops the dash offset, so the markup animates `stroke-dasharray` from `0 L` to `L 0` instead, where L is the length of the path. It looks the same and works in the browser too.

If you'd rather keep it in plain Flutter, the painter above is a starting point: take each path's `computeMetrics()`, draw `extractPath(0, metric.length * t)` and drive `t` with an `AnimationController`.

## What it doesn't convert

- **Gradients** are drawn with their first stop color, and patterns not at all. Flutter can do gradients with `Paint().shader`, but this tool doesn't write them.
- **Text, embedded images, masks, filters and `clipPath`** are skipped. The result lists everything that was skipped, so you can redraw it by hand or convert text to outlines in your editor first.
- **CSS in a `<style>` element** is not applied, only `style` attributes. Most editors can export with presentation attributes instead.
- **Group opacity** is folded into each shape's color, so overlapping shapes inside a semi-transparent group show through each other. **Dashed strokes** come out solid, since Flutter's `Paint` has no dash pattern.
- A stroke under a non-uniform scale or skew gets one averaged width, because Flutter strokes in canvas space.

## Sources

- [SVG 2, Paths](https://www.w3.org/TR/SVG2/paths.html) and [arc implementation notes](https://www.w3.org/TR/SVG2/implnote.html#ArcImplementationNotes) (W3C)
- [SVG 2, Basic shapes](https://www.w3.org/TR/SVG2/shapes.html) (how `rx`/`ry` default and clamp)
- [Path](https://api.flutter.dev/flutter/dart-ui/Path-class.html), [CustomPainter](https://api.flutter.dev/flutter/rendering/CustomPainter-class.html) and [PathFillType](https://api.flutter.dev/flutter/dart-ui/PathFillType.html) in the Flutter API docs

## FAQ

### How do I convert an SVG path to a Flutter Path?

Each SVG path command maps to a Path method: M to moveTo, L, H and V to lineTo, C and S to cubicTo, Q and T to quadraticBezierTo, Z to close. Arcs have no direct one-to-one call once transforms are applied, so they are converted to cubic Béziers. Paste the SVG above and copy the generated code.

### Can I use an SVG in CustomPaint?

Not directly: CustomPaint draws with Canvas calls, not SVG markup. Convert the SVG to a CustomPainter that builds Path objects and draws them with Paint, which is what this tool generates, including a small widget that wraps it in CustomPaint.

### Does Flutter support SVG natively?

No. Flutter has no built-in SVG widget; the usual way to show an SVG file is the flutter_svg package. Converting an icon to a CustomPainter avoids the dependency and gives you the Path to work with in code.

### What does PathFillType.evenOdd do?

It is Flutter's version of SVG's fill-rule="evenodd": a region is filled if a line from it crosses the path an odd number of times. It is what cuts holes in shapes like rings and letters drawn as one path. The converter sets it wherever the SVG asks for evenodd.

### How do I animate an SVG path drawing itself in Flutter?

In plain Flutter, take the Path's computeMetrics() and draw extractPath(0, length * t) as t goes from 0 to 1. With an animated SVG, animate stroke-dasharray from "0 L" to "L 0"; the second code block above generates that markup and the widget that plays it.

### Why does the converted icon look different from the original?

Usually because the SVG uses something a Path cannot hold: gradients, text, masks, filters, clip paths or a <style> stylesheet. The tool lists everything it skipped or approximated under the result; compare the two previews to see the difference.

### Is my SVG uploaded anywhere?

No. The file is read and converted by JavaScript in your browser, and nothing is sent to a server.
