openGalleryPhoto method
Implementation
Future openGalleryPhoto() async {
List<Media>? res = await ImagesPicker.pick(
pickType: widget.cameraPick == CameraPick.photo
? PickType.image
: PickType.video,
count: widget.cameraPick == CameraPick.photo ? widget.maxPick ?? 1 : 1,
// maxTime: timeEnd,
maxSize: 50,
gif: false,
language: Language.English,
);
if (widget.cameraPick == CameraPick.photo) {
if (res != null) {
List<ImageModulModel> imageSelected = [];
res.forEach((element) async {
List iu = element.path.split(".");
String mytype = iu.last.toString();
String pathfile = element.path;
// if (mytype == "heic") {
// await HeicToJpg.convert(element.path).then((value) async {
// File result = await FlutterImageCompress.compressAndGetFile(
// value, value + ".jpg",
// quality: 20);
// if (result != null) {
// imageSelected
// .add(ImageModulModel(isSelected: true, file: result));
// } else {
// File file = File(element.path);
// // print("file type ${file.path}");
// imageSelected
// .add(ImageModulModel(isSelected: true, file: file));
// }
// if (res.length > 0) {
// if (res.length == imageSelected.length) {
// gotPreview(imageSelected, isGallery: true);
// }
// } else {
// openGalleryPhoto();
// }
// });
// } else {
//
//
// }
XFile? result = await FlutterImageCompress.compressAndGetFile(
pathfile, pathfile + ".jpg",
quality: Config.compresValue);
if (result != null) {
File file2 = File(result.path);
imageSelected.add(ImageModulModel(isSelected: true, file: file2));
} else {
File file = File(element.path);
imageSelected.add(ImageModulModel(isSelected: true, file: file));
}
print("resss s${res.length}");
if (res.length > 0) {
if (res.length == imageSelected.length) {
if (mounted) {
gotPreview(imageSelected, FileType.image, isGallery: true);
}
}
} else {
openGalleryPhoto();
}
});
}
} else {
File? file;
if (res != null) {
// print("resss ${res}")
file = File(res.first.path);
Future.delayed(Duration(seconds: 1)).then((value) {
if (mounted) {
SellonRouter.push(
context,
VideoPreviewFileNew(
timeEnd: timeEnd,
key: widget.key!,
videoFile: file!,
isFromCamera: false,
)).then((value) {
if (value == null) {
openGalleryPhoto();
} else {
if (value is List) {
widget.backVideo!(value);
}
}
});
}
});
} else {
// List<File> filess = [];
// filess.add(file!);
// widget.backVideo!(filess);
}
}
}