I made the code open source. So in case you want to see the code, use it in you CI pipeline or contribute, see the code on GitHub. Otherwise just use the live functionality on this page.
Convert your SVG file directly to Flutter paths and prevent all the messing with bezier curves. Just tap on the Convert SVG button, choose your SVG file and you can obtain the resulting Flutter code from the text field below. If you want to see real world example input and output, hit the respective buttons underneath. The examples are the ones from the howto.
Convert SVG
Example input
Example output
Copy code
Flutter code
Howto
This tutorial describes the usage including the SVG creation using an actual example.
Advantages
No manual dealing with code that creates bezier paths
The code that is being returned from the converter is designed to be rather readable (no long numbers with high precision) and can thus be edited afterwards
The converter supports multiple paths at once in the SVG file
It softens curves a little
The boundaries of the existing paths are detected automatically. So no values except for the SVG file need to be provided
Aside from path nodes in the SVG the converter also converts rect and circle nodes
Colors are recognized from the shapes and find their representation in the output as well
Caveats
For the converter to properly convert the SVG into a Path it is recommended to put everything to (0,0) of the canvas (except for the paths that are supposed to be shifted)
If padding is desired, a rect should be wrapped around everything with the respective padding towards every shape
Every group in the SVG should be dissolved before the conversion as it can lead to side-effects
I’m looking for an option to run it offline, i can think of a few potential usages of this tool. Do you still think about going open source with that? :)
Oh yes, thank you for reminding me. I have a lot on my list right now, but I will contact you via e-mail!
Kind regards!
Andriy
@marc thanks a lot for such a cool tool. Just have an idea: can you please somehow run MyPainter in inside a Flutter app in the web, so every one can preview result painter on the same page? like here : https://api.flutter.dev/flutter/widgets/Form-class.html (where you have a “Run” button)?
I don’t fully understand your issue.
As you can see, size.height does come up in the CustomPainter which means that the height is actually taken into account.
You might need to wrap you CustomPaint widget with a SizedBox to control the height.
I tried it here: https://imgur.com/Fbq5dXZ - this is height 300 and width 300. If I change the height, the proportions change with it.
Further more, white piano key that should be easier as it doesn’t have any 3d effects, doesn’t work at all…
Here is the code:
image/svg+xml
https://imgur.com/a/wKPrlzR
On the image you can see keys on right are ones I imported as svg in flutter and one on right is what I get when using your converter
Hope you could help me out figure what is wrong and if it is possible at all to have 3d effects using your tool, I guess maybe your converter works just with one layer? and in order to get 3d effect, your converter should be able to convert svg into multiple layers?
Layers should not be a problem. Gradients though, as I only extract the fill color. Also, groups are a problem. If you ungroup everything, it should work. You can set gradients afterwards.
You SVG code is very messy. A transformation of -402.445, 166.218. I cleaned up the file and uploaded it: https://pastebin.com/18uGQhfJ. The respective Dart code is also in there.
Hi there,
still playing around a bit … why not make the colors const likepaint.color = const Color(0xffffffff); and also giving the class a const constructor?
you also wanted to make this open source¿? what happened to those plans? I’m thinking of integrating this into my buildrunner 🙃
Thanks for this amazing tool. For me it threw an error in the browser console when I defined the fill tag on a path. It would be nice if that got fixed.
After figuring that out I was able to use the tool normally.
1.) I create a CustomPaint widget inside a Container of width:300,height:300,color: Colors.amberAccent,
2.) I create an inkscape drawing with dimensions larger than what I need
3.) I drag guide lines to the 300/300 marks
4.) I draw the path that I need
Hey Martin, you’re correct with what you’re saying. That’s why I had stated this in the caveats:
If padding is desired, a rect should be wrapped around everything with the respective padding towards every shape
So instead of creating a line, you might as well go for a white or transparent background rectangle.
Other than that, you are correct and I might as well update the tool.
Without having seen your SVG file, it’s hard for me to find out why it didn’t work. Have you followed the instructions listed under caveats? If you have and it still does not work, please contact me. I will respond and you can send me the file via SVG. Optionally, you might want to share the file on pastebin as response to this comment.
Please check your convert.js script. I noticed shapesToFlutterCodeConverter() doesn’t give all mandatory params: width, height, and config. So… the converter at a website not working correctly but locally, after applying these changes everything is fine.
Hi, this online tool is using the same updated version from github? I get some SVGs converted with some glitches (some curves are not correct mapped from svg to flutter). I make sure svg is closed as well
no, actually the version here is rather old and differs from the other version. The other version uses node packages whereas here on the website I use the CDN version of certain packages.
Hey Marc,
awesome tool! Used it 2 years ago and now here I am again. But this time i noticed some visual issues.
#1
I found out that when you have more than 2 decimals this tool rounds them to max 2 decimals.
It would be great if there would be an option to allow e.g. 3 or more decimal places to be parsed.
The asset I use as an input gets weird roundness shapes due to the relatively unprecise decimal places.
Especially if the tool outputs cubitTo this visual bug occurs.
#2
Most of the assets I want to convert are compound. By default, this tool uses “lineTo” instead of “moveTo” when there are jumps between points. This should be defaulted to “moveTo” in order to not draw lines between shapes that should not exist.
You can also invite me to your repo (if possible), I could help fixing the issue.
These are totally valid points. Would you mind creating the respective PRs in my
GitHub Repo? I will gladly merge them if they fix the mentioned issues.
test
Marc
In reply to test's comment
Nagaraj Alagusundaram
Marc
In reply to Nagaraj Alagusundaram's comment
Nagaraj Alagusundaram
In reply to Marc's comment
Wojtek
In reply to Marc's comment
Marc
In reply to Wojtek's comment
Andriy
Marc
In reply to Andriy's comment
Victor
Marc
In reply to Victor's comment
Ahmed Fwela
Marc
In reply to Ahmed Fwela's comment
jckodel
Marc
In reply to jckodel's comment
Jani
Marc
In reply to Jani's comment
ch rohith
Marc
In reply to ch rohith's comment
Carl2393
Marc
In reply to Carl2393's comment
Su
pierre
Victor
Victor
In reply to Victor's comment
Leptopoda
kherel
kherel
In reply to kherel's comment
Ankit Sagar
PK
Joran
Martin
Marc
In reply to Martin's comment
Atish Paul
Joao
Marc
In reply to Joao's comment
hagen
Marc
In reply to hagen's comment
Kamil
Marc
In reply to Kamil's comment
Oleksii
Gil
Marc
In reply to Gil's comment
Marwin Lebensky
Marc
In reply to Marwin Lebensky's comment