我有图片的网络网址,我需要获取Uint8List。如何转换?
我检查类似问题的答案,但是这些方法不起作用。
How to get a Flutter Uint8List from a Network Image?

最佳答案

Uint8List yourVar;
final DecoderCallback callback = (Uint8List bytes, {int cacheWidth, int cacheHeight}) {
        yourVar = bytes.buffer.asUint8List();
        return instantiateImageCodec(bytes, targetWidth: cacheWidth, targetHeight: cacheHeight);
      };
ImageProvider provider = NetworkImage(yourImageUrl);
    provider.obtainKey(createLocalImageConfiguration(context)).then((key) {
      provider.load(key, callback);
    });

10-05 17:43