im using flutter_svg package for svg. and now i want to use a svg inside a container as decoration like this,
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: SvgPicture.string(
'''<svg viewBox="...">...</svg>'''
),
),
),
)
but the problem is DecorationImage peram expecting ‘ImageProvider’. how can i do this ?
i tried flutter_svg_provider but its also not working. i found this solution, but dont know how to use.
2
Answers
The SvgPicture is a Widget, not an Image, which is why it can not be used as DecorationImage here. The way you can use the SvgPicture behind your Container is a Stack:
Obviously, you have to make sure that both have the same size if you need it. But that depends on your usecase.
use a custom Decoration like this:
as you can see there are 3 constructors:
SvgDecoration.string
,SvgDecoration.file
andSvgDecoration.asset
but of course you can add some other custom constructors (likeSvgDecoration.network
for example)