无法将参数类型'String'分配给参数类型'Uint8List'

时间:2019-06-16 19:51:36

标签: image flutter dart

我的响应中包含base64String,并尝试将该base64转换为图像。我已经使用了Uint8List类https://api.dartlang.org/stable/2.4.0/dart-typed_data/Uint8List-class.html。但无法将转换后的base64引用到Image.memory。

class Data {
  String sId;
  String name;
  String category;
  String image;
  int iV;
  var decoded;
  Uint8List bytes ;

  Data({this.sId, this.name, this.category, this.image, this.iV, this.bytes});

  Data.fromJson(Map<String, dynamic> json) {
    sId = json['_id'];
    name = json['name'];
    category = json['category'];
    image = json['image'];
    iV = json['__v'];
 // decoded = Base64Decoder().convert(image);
   bytes = base64.decode(image);
  }

Container(     
margin: const EdgeInsets.symmetric(horizontal: 2.0),
                                          width: 100.0,
                                          height: 140.0,
                                          child:Image.memory('${data.bytes}'),
                                        ),

enter image description here

1 个答案:

答案 0 :(得分:0)

您应该这样写:

Container(     
margin: const EdgeInsets.symmetric(horizontal: 2.0),
                                          width: 100.0,
                                          height: 140.0,
                                          child:Image.memory(data.bytes),
                                        ),