71 lines
1.6 KiB
Dart
71 lines
1.6 KiB
Dart
|
|
import 'dart:io';
|
||
|
|
|
||
|
|
import 'package:fcs/widget/multi_img_file.dart';
|
||
|
|
|
||
|
|
typedef CallBack = void Function();
|
||
|
|
|
||
|
|
class MultiImgController {
|
||
|
|
List<String> imageUrls;
|
||
|
|
List<FileContainer> addedFiles = [];
|
||
|
|
List<FileContainer> removedFiles = [];
|
||
|
|
|
||
|
|
List<FileContainer> fileContainers = [];
|
||
|
|
CallBack callback;
|
||
|
|
MultiImgController() {
|
||
|
|
fileContainers = [FileContainer()];
|
||
|
|
}
|
||
|
|
|
||
|
|
set setImageUrls(List<String> imageUrls) {
|
||
|
|
if (imageUrls == null) {
|
||
|
|
fileContainers.add(FileContainer());
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
fileContainers.clear();
|
||
|
|
|
||
|
|
this.imageUrls = imageUrls;
|
||
|
|
imageUrls.forEach((e) {
|
||
|
|
fileContainers.add(FileContainer(url: e));
|
||
|
|
});
|
||
|
|
fileContainers.add(FileContainer());
|
||
|
|
if (callback != null) {
|
||
|
|
callback();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void onChange(CallBack callBack) {
|
||
|
|
this.callback = callBack;
|
||
|
|
}
|
||
|
|
|
||
|
|
set addFile(FileContainer fileContainer) {
|
||
|
|
// if (fileContainers.contains(fileContainer)) return;
|
||
|
|
addedFiles.add(fileContainer);
|
||
|
|
fileContainers.add(FileContainer());
|
||
|
|
if (callback != null) {
|
||
|
|
callback();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
set removeFile(FileContainer fileContainer) {
|
||
|
|
if (!fileContainers.contains(fileContainer)) return;
|
||
|
|
fileContainers.remove(fileContainer);
|
||
|
|
|
||
|
|
if (addedFiles.contains(fileContainer)) {
|
||
|
|
addedFiles.remove(fileContainer);
|
||
|
|
}
|
||
|
|
if (imageUrls.contains(fileContainer.url)) {
|
||
|
|
removedFiles.add(fileContainer);
|
||
|
|
}
|
||
|
|
if (callback != null) {
|
||
|
|
callback();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
List<File> get getAddedFile {
|
||
|
|
return addedFiles.map((e) => e.file).toList();
|
||
|
|
}
|
||
|
|
|
||
|
|
List<String> get getDeletedUrl {
|
||
|
|
return removedFiles.map((e) => e.url).toList();
|
||
|
|
}
|
||
|
|
}
|