Flutter SVG rendering

Multi tool use
Multi tool use


Flutter SVG rendering



I tried adding an image with a SVG source to my flutter application.



new AssetImage("assets/images/candle.svg"))


new AssetImage("assets/images/candle.svg"))



But I didn't get any visual feedback.
How can I render an SVG picture in Flutter?




4 Answers
4



Flutter does not currently support SVG. Follow issue 1831 for updates.



If you absolutely need vector drawing you can see the Flutter Logo widget as an example of how to draw using the Canvas API, or rasterize your image on the native side and pass it to Flutter as a bitmap, but for now your best bet is probably to embed high-resolution rasterized asset images.


Canvas





Also if you don't need color, you can always go the font route the way the Icons package does.
– prodaea
Mar 1 at 20:22



The work around for now is use fonts



https://icomoon.io/


fonts:
- family: icomoon
fonts:
- asset: assets/fonts/icomoon.ttf



Useage


static const IconData TabBarHome= const IconData(0xe906, fontFamily: 'icomoon');
static const IconData TabBarExplore= const IconData(0xe902, fontFamily: 'icomoon');



Replace the ### eg (906)





try fluttericon.com
– Boni2k
Apr 11 at 12:20



Fonts are a great option for a lot of cases.



I've been working on a library to render SVGs on a canvas, available here:
https://github.com/dnfield/flutter_svg



The API as of right now would look something like


new SvgPicture.asset('asset_name.svg')



to render asset_name.svg (sized to its parent, e.g. a SizedBox). You can also specify a color and blendMode for tinting the asset..


SizedBox


color


blendMode



It's now available on pub and works with a minimum of Flutter version 0.3.6. It handles a bunch of cases but not everything - see the GitHub repo for updates and to file issues.



The original GitHub issue referenced by Colin Jackson is really not meant to be primarily focused on SVG in Flutter. I opened another issue here for that: https://github.com/flutter/flutter/issues/15501



Flutter made a new lib flutter_svg: ^0.5.0 for handle svg files. We can use it as


flutter_svg: ^0.5.0


new SvgPicture.asset(
'assets/images/candle.svg',
height: 20.0,
width: 20.0,
allowDrawingOutsideViewBox: true,
),






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

gYf08siBKKiUH8o1i hyYin R07Lny,MxxV
4cZj28Ud,sDXekgMfwLII,73RlxAt9gDzhz hMH2Zbi5yf3RCgoaRIJqGd8,ygd5Ip 7,0VNKvhpEC2HDWiNecQATDDuiQcsiWbcbC7E

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications