Open dr953 opened 1 year ago
I know this is old, but I also had a similar experience with migrating and how to preserve scaling. I was also using scaleCanvasToViewBox
previously:
DrawableRoot image;
image.scaleCanvasToViewBox(canvas, size);
image.draw(canvas, Rect.zero);
and ended up replacing that with
paintImage(
canvas: canvas,
rect: Rect.fromLTWH(0, 0, size.width, size.height),
image: pictureInfo.picture.toImageSync(
pictureInfo.size.width.toInt(),
pictureInfo.size.height.toInt(),
),
);
I'm also trying to understand what happened to DrawableRoot and how to do what I used to do with it. Here's what I found: the package parses svg and compiles it into "bytecode". Later you can decode that bytecode and extract the shapes from it.
final loader = SvgStringLoader(svgString);
final byteData = await loader.loadBytes(context);
final codec = VectorGraphicsCodec();
// listener should implement VectorGraphicsCodecListener.
codec.decode(byteData, listener);
You'll need to add a dependency to the https://pub.dev/packages/vector_graphics_codec package. Feel free to check out https://pub.dev/documentation/vector_graphics_codec/latest/vector_graphics_codec/VectorGraphicsCodec/decode.html and https://pub.dev/documentation/vector_graphics_codec/latest/vector_graphics_codec/VectorGraphicsCodecListener-class.html for more information.
You can read my still incomplete notes at https://www.wafrat.com/upgrading-to-flutter_svg-2-0-0/.
Could you please share a snippet to help me migrate some v1 features? I have a hard time finding the info in the reference.
And then, creating a new DrawableRoot (PictureInfo) for the picked children:
Should
be replaced with scaling of the canvas itself, before:
or is there a replacement function for the v1
scaleCanvasToViewBox