addImage method

Future<void> addImage(
  1. int i,
  2. XFile? xFile,
  3. String prefix
)

Move the image into proof Directory and register it as a proof.

Implementation

Future<void> addImage(int i, XFile? xFile, String prefix) async {
  if (xFile == null) return;
  //
  // > create new path
  //
  final newPath = await proofPath(i.toString());
  if (newPath == null) return;
  //
  // > move file to group path
  //
  final tmpImgFile = File.fromRawPath(
    Uint8List.fromList(utf8.encode(xFile.path)),
  );
  final imgFile = tmpImgFile.copySync(
    path.join(
      newPath.path,
      '${prefix}img_${path.basename(xFile.path)}',
    ),
  );
  tmpImgFile.deleteSync();
  //
  // > update list
  //
  if (prefix == 'after_') {
    proofs[i].after.image = Image.file(imgFile);
  } else {
    proofs[i].before.image = Image.file(imgFile);
  }
  notify();
}