简体   繁体   中英

The argument type 'String' can't be assigned to the parameter type 'Uint8List'

I'm having a base64String in my response and trying to convert that base64 to image. I have used the Uint8List class https://api.dartlang.org/stable/2.4.0/dart-typed_data/Uint8List-class.html . but cannot reference my converted base64 to 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

You should write like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM