-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change colors for multi color svg #372
Comments
See this website, they can change the color of svg |
You have style css support listed as out of scope. I hope you will consider at least supporting color styles as shown below. I have a bunch of svgs that are multi-color and the plugin renders them mono-colored. This is blocker for my use of this plugin and I've needed to revert all my svgs back to png 😩
|
I think probably extract the paths of SVG and convert that to flutter paths and render ? |
Supporting CSS is, quite frankly, a nightmare and a full time job. It is generally possible to preprocess any CSS away as well. For the original request of this bug, I don't have any plans to support this but would be open to reviewing patches that added it in some reasonable way. However, in general you should be able to work with the |
@dnfield that's what I wanted.. can you suggest a recommended way to hook the style of Drawable* class from outside of flutter_svg ? that's from my own code? |
From the readme: import 'package:flutter_svg/flutter_svg.dart'; // If you only want the final Picture output, just use // Otherwise, if you want to draw it to a canvas: // Optional, but probably normally desireable: ensure the SVG isn't rendered |
Thanks so much |
Hi, fantastic lib, thanks heaps. Quick question, I am using svgRoot.draw() and it draws the svg in black. How do we change the color to something else? |
We also came across this issue and solved it for now by loading the svg's markup directly from the DefaultAssetBundle and preprocess it by replacing the color code that should be changed. So you just have to make sure that the fill / stroke is set correctly in your svg. Especially if you want to replace black because many svg optimizers will remove that since it is the svg internal default color. class Icon extends StatelessWidget {
Icon(this.icon, {this.color = Colors.black});
final String icon;
final Color color;
@override
Widget build(BuildContext context) {
return FutureBuilder<String>(
future: DefaultAssetBundle.of(context).loadString("assets/icons/" + icon + ".svg"),
builder: (context, snapshot) {
return SvgPicture.string(
(snapshot.data ?? "<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 1 1\"></svg>")
.replaceAll("#000000", '#${this.color.value.toRadixString(16).padLeft(6, '0').toUpperCase()}'),
width: 32,
);
}
);
}
} |
Do you mean something like this? I call it SVG colorization. This tutorial can help to solve your issue. Not only does it changes the color, but also allows the user to download the manipulated SVG code. |
Found great answer here https://stackoverflow.com/questions/73034225/flutter-svg-gradient-is-not-rendered-failed-to-find-definition-for-url : |
You can create a custom ColorMapper supported many colors (see #856 (comment))
|
Thanks for your message but I found the workaround by setting condition and changing color dynamically something like this. |
Widget build(BuildContext context) {
} extension ColorHex on Color { |
enum MyIcons { const MyIcons ({required this.assetName}); final String assetName; class MyIcons extends Icon { const MyIcons ( |
Thanks for the awesome library first!.
I was wondering how can I change colours for a multi color svg for individual segments? Currently only one color is supported.
Thanks
The text was updated successfully, but these errors were encountered: