Reputation: 488
I'm trying to use Flutter SVG dependency, i put in the svg in assets, set in pubspec.yaml, and set in my widget, but, the svg load with black container
I've already tried change the svg, and the another svg works fine, but the other not...
final Widget svg = SvgPicture.asset(assetName, semanticsLabel: 'Acme Logo');
the svg in flutter
My expected response was colored svg like the link in codepen, but i got this
Upvotes: 14
Views: 23044
Reputation: 1
delete your pubspec.lock file and do flutter clean -> flutter pub get-> run your application.
Upvotes: -1
Reputation: 348
The issue is that The flutter_svg
is unable to load the css written inside style
tag. flutter_svg
only support inline css . Write inline css instead of inside the style
tag
Upvotes: 1
Reputation: 1873
Instead of cleaning the SVG file , which is not acceptable for app client to clean every SVG he need it
https://pub.dev/packages/jovial_svg
ScalableImageWidget.fromSISource(
si: ScalableImageSource.fromSvgHttpUrl(
Uri.parse(imgPath),
),
),
Upvotes: 1
Reputation: 131
use this configuration in illustrator before you add it to your project.
https://user-images.githubusercontent.com/2842459/62599914-91de9c00-b8fe-11e9-8fb7-4af57d5100f7.png
Upvotes: 3
Reputation: 141
I found this site it solved my problem with the svg file that was out of color.
https://iconly.io/tools/svg-cleaner
Upvotes: 5
Reputation: 592
I think I am late but this might just help someone. Just make all the styles in your svg image use inline styling otherwise all colors and styling won't be rendered as the tag is not readable by the SvgPicture.
Upvotes: 3
Reputation: 421
I tried this SVG asset with the latest version of jovial_svg
, and it works great! Here's the result:
This version of jovial_svg
should be released in a couple of days, but for now it's 1.1.4-rc.4.
(This asset helped me flesh out stylesheet support - thanks!)
Upvotes: 1
Reputation: 766
Some SVG images uses style tag and if you try to load such image using flutter_svg, image won't render as expected. Currently flutter_svg supports styling through inline styles only and not the style tag that some of SVG files may contain (in my case, I exported image from Adobe XD and it has all styles in tag). When you try to load such SVG images, you will get below error:
======== Exception caught by SVG =================================================================== The following UnimplementedError was thrown in parseSvgElement: The
element is not implemented in this library. Style elements are not supported by this library and the requested SVG may not render as intended. If possible, ensure the SVG uses inline styles and/or attributes (which are supported), or use a preprocessing utility such as svgcleaner to inline the styles for you.
This error mentions to use inline style instead of style tag, you can use svgcleaner (as mentioned in @Alif's answer) or similar utility to convert SVG file with inline styling.
For more detials, refer this link to check SVG compatibility with flutter_svg and handling other use-cases
Upvotes: 0
Reputation: 915
This is probably happened because of the corrupted SVG files from the internet. I faced this problem earlier and tried many ways to solve it. But finally, I solved it with the help of this software, svgcleaner.
Download the application into your OS, from here
After installation,
After cleaning, you can grab those SVG files from the output folder location and add those files into your flutter app without seeing any black coloured SVG.
It works perfectly fine like this.
Upvotes: 29
Reputation: 1
If You don't have solution try to convert your image from svg to png and use:
Image.asset('assets/images/image.png',)
Upvotes: 0
Reputation: 105
try this:
Container(
child: SvgPicture.asset(
'assets/images/image.svg',
fit: BoxFit.contain,
),
)
Upvotes: -5