我必须从 base64 读取图像源才能进行 flutterImage https://api.flutter.dev/flutter/widgets/Image-class.html object.
Image img = Image.memory(base64Decode(BASE64_STRING));
然后我想将图像作为容器背景。但 DecorationImage 只接受图像提供者 https://api.flutter.dev/flutter/painting/ImageProvider-class.html.
如何将图像转换为ImageProvider?或者还有其他方法将 base64 图像传递给 ImageProvider 吗?
Container(
decoration: BoxDecoration(
color: Colors.green,
image: DecorationImage(
image: img // <-- Expecting ImageProvider
)
)
Call .image
在你的Image
得到ImageProvider
.
例如假设:
Image img = Image.asset('assets/logo.png');
在你的情况下:
Container(
decoration: BoxDecoration(
color: Colors.green,
image: DecorationImage(
image: img.image // <--- .image added here
)
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)