Menu

Draw an SVG icon in Flutter without a package: SVG path commands to CustomPainter
📰

Draw an SVG icon in Flutter without a package: SVG path commands to CustomPainter

DEV Community: dart·Chanpenh Yorn·19 days ago
#n10yuWCM
#devtodart#devto#dev#size#const
Reading 0:00
15s threshold

flutter_svg is the right answer when you need to show a lot of SVG files. But for a single icon you want to animate, recolour per path, clip with, or ship with zero dependencies, a plain CustomPainter is often nicer. The good news: SVG path data maps almost one to one onto Flutter's Path API.

The command table

SVG Flutter Path

M x y moveTo(x, y)

L x y lineTo(x, y)

H x / V y lineTo with the other coordinate unchanged

C x1 y1 x2 y2 x y cubicTo(x1, y1, x2, y2, x, y)

Q x1 y1 x y quadraticBezierTo(x1, y1, x, y)

A rx ry rot large sweep x y arcToPoint(Offset(x, y), radius: Radius.elliptical(rx, ry), rotation: rot, largeArc: large == 1, clockwise: sweep == 1)

Z close()

Lowercase (relative) commands have relative… versions ( relativeLineTo , relativeCubicTo , relativeArcToPoint and so on), or you can add the current point yourself.

Two commands have no direct method:

S and T are "smooth" curves.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.