pickImagesToByte static method

Future<List<ByteData>?> pickImagesToByte(
  1. BuildContext context, {
  2. bool usingCamera = true,
  3. bool usingGallery = true,
  4. bool allowMultiple = true,
  5. int? maxSize,
})

Implementation

static Future<List<ByteData>?> pickImagesToByte(BuildContext context,
    {bool usingCamera = true, bool usingGallery = true, bool allowMultiple = true, int? maxSize}) async {
  List<ResultItem>? images = await _pickImages(
    context,
    usingCamera: usingCamera,
    usingGallery: usingGallery,
    allowMultiple: allowMultiple,
    maxSize: maxSize,
  );

  if (images == null) return null;

  List<ByteData> datas = <ByteData>[];

  for (ResultItem item in images) {
    final data = await _readFileByte(item.filePath);
    datas.add(data);

    if (item.albumId == null) {
      File cameraImage = File(item.filePath);

      bool fileExists = await cameraImage.exists();

      if (!fileExists) {
        cameraImage.deleteSync();
      }
    }
  }

  return datas;
}