-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v2.0.5] Svg not properly resized when passed to vg.loadPicture() #971
Comments
Did you find any workaround for this or maybe another way to implement it? |
@HasanShaddadKangaroo I ended up parsing the svg string myself by doing the following steps:
Applying the scale without modifying all height, width and viewBox doesn't work. It's a 25 lines workaround that's blind enough to the SVG syntax for us to use, but it's also because we know how our SVGs are written. |
I've forked the repo and made a hacky fix for that, I most likely won't create a PR unless Dan himself says otherwise - the reason being it most likely isn't a proper solution (but more of a workaround) Import using: flutter_svg:
git:
url: https://github.com/XperiTech/flutter_svg
path: packages/flutter_svg
ref: e969f6c510949eee75b3e93269411e8815fd1f45 ( The way you can use it is by specifying await vg.loadPicture(
SvgStringLoader(svgString),
context,
targetSize: Size(80, 80),
); the code inside will calculate how much it should scale each axis ( final double sx = targetWidth / width;
final double sy = targetHeight / height; and then it will choose the smallest one to scale the svg: _canvas.scale(min(sx, sy)); |
I think if you add some tests for this it would be a reasonable way to handle this upstream. |
Some news about this ? |
I solved it this way in my agony, I'm waiting for the error correction so that I can delete the seemingly unnecessary subsequent resizing.
|
I am using flutter_svg to handle SVG files that needs to be resized before getting formatted as PNGs to be used as markers on GoogleMap (why GoogleMap doesn't handle SVG is beyond me, but not the topic of this post). Because I haven't find a way to convert an
SvgPicture
directly intoByteData
with theImageByteFormat.png
format, I'm doing a bit of a workaround by converting it into an Image first.I follow what was recommended here. However, no matter what value I give to
width
andheight
, the file will be shown in its original size. As far as I can tell, the bytesLoader ignores the values passed toSvgPicture.asset()
and uses the one inside the file instead (see picture below).I'm not sure if it's intended or not, but it's at the very least counterintuitive in my opinion.
The text was updated successfully, but these errors were encountered: