loadDownloadList static method
Implementation
static loadDownloadList(
Function(List<List<ScanModel>>? list)? callBack) async {
Directory dir = await getApplicationDocumentsDirectory();
String folderName = "${dir.path}/lesntec_download";
Directory realDir = Directory(folderName);
bool isExist = realDir.existsSync();
if (isExist) {
realDir.list().toList().then((value) async {
if (value.isNotEmpty) {
List<List<ScanModel>> modelList = [];
for (FileSystemEntity element in value) {
Directory temp = Directory(element.path);
List<ScanModel> subModelList = [];
if (temp.existsSync()) {
var res = await temp.list().toList();
for (var value2 in res) {
String name = UnitsDataTool.converFileName(value2.path);
List splitStr = name.split(".");
String realName = splitStr.first;
List<ScanModel>? scanModelList =
await UnitsForSqlite.queryDataListWithName(realName);
ScanModel? scanModel;
if (scanModelList != null && scanModelList.isNotEmpty) {
if (scanModelList.length == 1) {
scanModel = scanModelList.first;
} else {
for (var element in scanModelList) {
if (element.id == realName) {
scanModel = element;
}
}
}
}
Map tempMap = jsonDecode(scanModel!.params!);
tempMap["filePath"] = value2.path;
scanModel.params = jsonEncode(tempMap);
subModelList.add(scanModel);
}
if (subModelList.isNotEmpty) {
modelList.add(subModelList);
}
}
}
if (callBack != null) {
callBack(modelList);
}
}
debugPrint(value.toString());
});
} else {
if (callBack != null) {
callBack(null);
}
}
}