insertFiles method
Implementation
void insertFiles(List<FormeFile> files) {
if (!mounted || files.isEmpty) {
return;
}
final List<FormeFile> currentValue =
(_gridController.currentItems ?? _gridController.value)
.where((element) => element.value != null)
.map((e) => e.value!)
.toList();
final int num = currentValue.length;
final int? canInsertNums =
widget.maximum == null ? null : widget.maximum! - num;
if (canInsertNums != null && canInsertNums <= 0) {
return;
}
List<FormeFile> needInserts =
files.where((element) => !currentValue.contains(element)).toList();
if (needInserts.isEmpty) {
return;
}
if (canInsertNums != null && canInsertNums < needInserts.length) {
needInserts = needInserts.sublist(0, canInsertNums);
}
final List<FormeFile> list = [];
for (final FormeFile item in needInserts) {
if (!list.contains(item)) {
list.add(item);
}
}
_gridController.value = _convert(currentValue..addAll(list));
}