Skip to content

Flutter web color not working #1

@jefrisingh

Description

@jefrisingh

Below is your code with small modification for color, It's working on web but svg's only has one path element, it's not working if svg has more path elements, Can you please find the good solution,
I'm verymuch thankfull for your existing work , :),
P.S : look at hash generation on color, otherwise color chnage won't affect on web

if (kIsWeb) {
String hashCode = assetName.replaceAll('/', '-').replaceAll('.', '-');
return FutureBuilder(
future: rootBundle.loadString(assetName),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData) {
String svgString = snapshot.data;
if(null != color) {
String colorString = color.value.toRadixString(16).substring(2);
hashCode = "$hashCode-$colorString";
svgString = svgString.replaceAll(
'/>', " fill="#$colorString"/>");
print(svgString);
}
print(svgString);
return string(svgString,
width: width, height: height, hashCode: hashCode);
} else if (snapshot.hasError) {
return Container(
width: width,
height: width,
);
} else {
return Container(
width: width,
height: width,
);
}
});
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions