My colored SVG is rendered as black?
Hey, i have SVG images and they are colored, when i import one in my flutter app,it come in black color,while i did not set the color. what is the problem?
Same problem observed!
Why can't we just see the default svg color? I can see that my svg file is being brushed with the primary color.
I have same problem
Can you provide a sample SVG that demonstrates this?
@AresVampire your problem is using a style element which isn't supported - see #105
Try this: https://github.com/dnfield/flutter_svg/issues/105#issuecomment-479724077
You can watch this answer from StackOverflow
https://stackoverflow.com/a/62748066/11681472
Same problem, my SVG assets render black when using SvgPicture.asset. I do not believe they are corrupted as they display properly on my Mac and in Android Studio.
These are the settings I used when exporting from Illustrator and it worked. I think a couple big things here is
-
I made compound paths ( Object > Compound Path > Make ) Note: when doing this with multiple colors if I tried to make the entire thing a compound path it would mess up. So I made compound paths out of each color
-
Notice the option CSS Properties. I noticed when doing them inline I was able to get the results I was looking for. I don't know if my subsetting setting helped at all BUT I am fairly confident making sure my css was inline was a major factor.

flutter_svg can not understand Internal or Embedded CSS.
Hence you need to convert the internal css <style>.a{fill:#566e83;}</style> into inline css.
Example:-
Convert this <path class="a" ... to <path style="fill:#566e83;" ...
You can use freecodeformat to edit your svg files.
resolved: I use webview to display svg:
import 'package:webview_flutter/webview_flutter.dart';
Container(
height: 100,
width: 200,
child: WebView(
initialUrl: 'about:blank',
onWebViewCreated:
(WebViewController webViewController) async {
String svgText =
await rootBundle.loadString('assets/white-logo.svg');
String fileText =
'<html><style>html,body {background: #C2185B;padding: 0;margin: 0;} svg {width: 100vw; height: 100vh;}</style><body>' +
svgText +
'</body></html>';
webViewController.loadUrl(
Uri.dataFromString(
fileText,
mimeType: 'text/html',
encoding: Encoding.getByName('utf-8'),
).toString(),
);
},
),
)
Using a webview will you get you pretty complete SVG support. But it will also be pretty slow.
It's not a bad option if you have a really special and complex SVG that you want to show in full screen mode or something. But it's not a good one for showing e.g. an icon on a button :)
If you are using the Svgpicture.asset() omit the second parameter color: Colors.black;
const svg = 'assets/pic.svg';
// omit the second color parameter, and your colors will be visible.
SvgPicture.asset(svg,
color: Colors.black,
semanticsLabel: 'My SVG Picture'
);
// something like this.
SvgPicture.asset(svg,
semanticsLabel: 'My SVG Picture'
);
In my case, i just re-run project, i feel after adding asset svg file will work fine only after re-run project.
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
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
This definitely solves the issue! thank you @iamprawesh
flutter_svg can not understand Internal or Embedded CSS.
Hence you need to convert the internal css
<style>.a{fill:#566e83;}</style>into inline css.Example:- Convert this
<path class="a" ...to<path style="fill:#566e83;" ...You can use freecodeformat to edit your svg files.
Works like a charm, thank you very much 🙏
@AresVampire your problem is using a style element which isn't supported - see #105
Thank you ! it works
resolved: I use webview to display svg:
import 'package:webview_flutter/webview_flutter.dart';
Container( height: 100, width: 200, child: WebView( initialUrl: 'about:blank', onWebViewCreated: (WebViewController webViewController) async { String svgText = await rootBundle.loadString('assets/white-logo.svg'); String fileText = '
' + svgText + ''; webViewController.loadUrl( Uri.dataFromString( fileText, mimeType: 'text/html', encoding: Encoding.getByName('utf-8'), ).toString(), ); }, ), )
Thanks, this was the best options out there. Especially when you are rendering third part svg icons that you have no control over. Also for those saying it's pretty slow . The only difference I noticed was about like 1 second, but that's not much considering the trade off of having no icon or a black one