Flutter SVG rendering

后端 未结 7 540
花落未央
花落未央 2020-12-03 02:27

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

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

But I didn\'t get any visual

相关标签:
7条回答
  • 2020-12-03 02:48

    You can follow the below steps
    - visit http://fluttericon.com
    - upload your SVG icons
    - click on download button
    - you will get two files
    1. iconname.dart
    2. iconname.ttf font file
    - use this file in flutter & import iconname.dart

    0 讨论(0)
  • 2020-12-03 02:49

    You can use this library for rendering SVG Images - https://pub.dev/packages/flutter_svg

    Example -

    Container(
        child: SvgPicture.asset("assets/images/yourImage.svg")
    )
    
    0 讨论(0)
  • 2020-12-03 02:53

    Developers from the Flutter community created a lib to handle svg files. We can use it as

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

    I found a small example of SVG implementation here.

    0 讨论(0)
  • 2020-12-03 02:54

    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.

    0 讨论(0)
  • 2020-12-03 03:00

    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)

    0 讨论(0)
  • 2020-12-03 03:02

    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..

    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

    0 讨论(0)
提交回复
热议问题