loadImage static method

dynamic loadImage(
  1. String id,
  2. String assetPath, {
  3. dynamic draw,
})

Implementation

static loadImage(String id, String assetPath, {draw}) async {
  if (iconMap[id] != null) {
    if (draw != null) {
      drawImage(id,draw['c'], draw['p'], iconMap[id], draw['imageSize'],draw['isCircle'],draw['borderColor'], draw['x'],draw['y'], draw['w'], draw['h']);
    }
  } else {
    if(loadMap[id] == null){
      if(assetPath.toLowerCase().contains('http')){
        final response = await http.get(Uri.parse(assetPath));
        final codec = await ui.instantiateImageCodec(response.bodyBytes);
        final frame = await codec.getNextFrame();
        ui.Image image = frame.image;
        iconMap[id] = image;
        loadMap[id] = image;
      }else{
        final ByteData data = await rootBundle.load(assetPath);
        final bytes = data.buffer.asUint8List();
        ui.Image image = await decodeImageFromList(bytes);
        iconMap[id] = image;
        loadMap[id] = image;
      }
    }
  }
  return iconMap[id];
}