2020-09-17 06:02:48 +06:30
|
|
|
import 'dart:io';
|
|
|
|
|
|
2020-10-13 07:50:25 +06:30
|
|
|
import 'callbacks.dart';
|
2020-09-17 06:02:48 +06:30
|
|
|
import 'display_image_source.dart';
|
|
|
|
|
|
|
|
|
|
class MultiImgController {
|
2020-10-19 12:41:13 +06:30
|
|
|
List<String> imageUrls = [];
|
2021-09-10 16:48:24 +06:30
|
|
|
List<File?> imageFiles = [];
|
2020-09-17 06:02:48 +06:30
|
|
|
List<DisplayImageSource> addedFiles = [];
|
|
|
|
|
List<DisplayImageSource> removedFiles = [];
|
|
|
|
|
|
|
|
|
|
List<DisplayImageSource> fileContainers = [];
|
2021-09-10 16:48:24 +06:30
|
|
|
CallBack? callback;
|
2020-09-17 06:02:48 +06:30
|
|
|
MultiImgController() {
|
|
|
|
|
fileContainers = [];
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-23 16:28:08 +06:30
|
|
|
set setImageUrls(List<String>? imageUrls) {
|
2020-09-17 06:02:48 +06:30
|
|
|
if (imageUrls == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
fileContainers.clear();
|
|
|
|
|
|
|
|
|
|
this.imageUrls = imageUrls;
|
|
|
|
|
imageUrls.forEach((e) {
|
|
|
|
|
fileContainers.add(DisplayImageSource(url: e));
|
|
|
|
|
});
|
|
|
|
|
if (callback != null) {
|
2021-09-10 16:48:24 +06:30
|
|
|
callback!();
|
2020-09-17 06:02:48 +06:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-23 16:28:08 +06:30
|
|
|
set setImageFiles(List<File>? imageFiles) {
|
2020-12-03 08:26:58 +06:30
|
|
|
if (imageFiles == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fileContainers.clear();
|
|
|
|
|
|
|
|
|
|
this.imageFiles = imageFiles;
|
|
|
|
|
imageFiles.forEach((e) {
|
|
|
|
|
fileContainers.add(DisplayImageSource(file: e));
|
|
|
|
|
});
|
|
|
|
|
if (callback != null) {
|
2021-09-10 16:48:24 +06:30
|
|
|
callback!();
|
2020-12-03 08:26:58 +06:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 06:02:48 +06:30
|
|
|
void onChange(CallBack callBack) {
|
|
|
|
|
this.callback = callBack;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set addFile(DisplayImageSource fileContainer) {
|
|
|
|
|
// if (fileContainers.contains(fileContainer)) return;
|
|
|
|
|
addedFiles.add(fileContainer);
|
|
|
|
|
if (callback != null) {
|
2021-09-10 16:48:24 +06:30
|
|
|
callback!();
|
2020-09-17 06:02:48 +06:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set removeFile(DisplayImageSource fileContainer) {
|
|
|
|
|
if (!fileContainers.contains(fileContainer)) return;
|
|
|
|
|
fileContainers.remove(fileContainer);
|
|
|
|
|
|
|
|
|
|
if (addedFiles.contains(fileContainer)) {
|
|
|
|
|
addedFiles.remove(fileContainer);
|
|
|
|
|
}
|
|
|
|
|
if (imageUrls.contains(fileContainer.url)) {
|
|
|
|
|
removedFiles.add(fileContainer);
|
|
|
|
|
}
|
2020-12-03 08:26:58 +06:30
|
|
|
|
|
|
|
|
if (imageFiles.contains(fileContainer.file)) {
|
|
|
|
|
this.imageFiles.remove(fileContainer.file);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 06:02:48 +06:30
|
|
|
if (callback != null) {
|
2021-09-10 16:48:24 +06:30
|
|
|
callback!();
|
2020-09-17 06:02:48 +06:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-10 16:48:21 +06:30
|
|
|
List<File?> get getUpdatedFile {
|
2021-09-10 14:25:37 +06:30
|
|
|
List<File?> _addfiles = getAddedFile;
|
2021-09-10 17:14:59 +06:30
|
|
|
this.imageFiles.addAll(_addfiles);
|
2020-12-03 08:26:58 +06:30
|
|
|
return this.imageFiles;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-10 14:25:37 +06:30
|
|
|
List<File?> get getAddedFile {
|
2020-09-17 06:02:48 +06:30
|
|
|
return addedFiles.map((e) => e.file).toList();
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-10 14:25:37 +06:30
|
|
|
List<String?> get getDeletedUrl {
|
2020-09-17 06:02:48 +06:30
|
|
|
return removedFiles.map((e) => e.url).toList();
|
|
|
|
|
}
|
|
|
|
|
}
|