【发布时间】:2020-05-10 16:31:36
【问题描述】:
我有图像的网络 url,我需要获取 Uint8List。我怎样才能转换它? 我检查类似问题的答案,但这些方法不起作用。 How to get a Flutter Uint8List from a Network Image?
【问题讨论】:
-
“不工作”是什么意思?
-
这意味着,该代码对于最新版本的 Flutter 是不实际的。
var load = sunImage.load(val);方法加载需要两个必填参数NetworkImageKey和DecoderCallback -
final DecoderCallback callback = (Uint8List bytes, {int cacheWidth, int cacheHeight}) { print(bytes.length); return instantiateImageCodec(bytes, targetWidth: cacheWidth, targetHeight: cacheHeight); }; ImageProvider provider = AssetImage('images/bg.png'); provider.obtainKey(createLocalImageConfiguration(context)).then((key) { provider.load(key, callback); });我用AssetImage测试过,但它应该适用于任何ImageProvider -
没什么,
provider.load(key, callback)被调用了 -
什么时候必须调用
print(bytes.length)?