upLoadImageString static method

Future<DataResult> upLoadImageString(
  1. List<String> list, [
  2. bool id = true
])

Implementation

static Future<DataResult> upLoadImageString(List<String> list,
    [bool id = true]) async {
  int position = -1;
  List<String> listId = [];
  next() async {
    position++;
    String? imageUrl = list[position];
    if (imageUrl.startsWith('http') == false) {
      String? image = await BaseDao.compressImage(imageUrl);
      var name = image.substring(image.lastIndexOf('/') + 1, image.length);
      FormData formData = FormData.fromMap(
          {'file': MultipartFile.fromFileSync(image, filename: name)});
      var res = await BaseDao.fromBaseJson(formData, Address.upLoadImage());
      if (res.result) {
        var entity = TokenEntity.fromJson(res.data);
        if (id) {
          listId.add(entity.id ?? '');
        } else {
          listId.add(entity.imageUrl ?? '');
        }
        if (position != list.length - 1) return await next();
        return DataResult(listId, true);
      }
      return res;
    } else if (position != list.length - 1) {
      return await next();
    }
    return DataResult(listId, true);
  }

  return await next();
}