downloadingFile method
void
downloadingFile(
- dynamic callback(
- bool isSuccess
)
)
Implementation
void downloadingFile(Function(bool isSuccess) callback) async {
String api = "http://192.168.43.1:8888$locPath";
Directory dir = await getApplicationDocumentsDirectory();
String folderName = "${dir.path}/lesntec_download/${model!.name}";
//创建文件夹
folderExists(folderName);
//文件名称
String zipName =
"$folderName/${model!.taskId}_${model!.actualOrder}_0${model!.splitNum == 0 ? '' : '_${model!.splitNum}'}.zip.flszip";
Map param = jsonDecode(model!.params!);
param["filePath"] = zipName;
model!.params = jsonEncode(param);
UnitsForNetwork.downloadData(
api,
savePath: zipName,
onSuccess: (res) async {
//存入数据库
if (model!.splitNum == 0) {
ScanModel? tempModel = await UnitsForSqlite.queryData(
model!.taskId!, model!.actualOrder!);
if (tempModel == null) {
UnitsForSqlite.insertData(model!);
}
} else {
UnitsForSqlite.insertData(model!);
}
Navigator.pop(currentContext!);
if (model!.upload!) {
//下载完立刻上传
showLoading(currentContext, "上传中");
//断开扫描仪链接
wifiDisconnect(callback: (isSuccess) {
if (isSuccess) {
LesntecUnits.uploadFile([model!], callback: (isSuccess, msg) {
Navigator.pop(currentContext!);
if (isSuccess) {
Fluttertoast.showToast(msg: "上传完成");
} else {
Fluttertoast.showToast(msg: msg ?? "上传失败");
}
});
} else {
Fluttertoast.showToast(msg: '切换wifi失败,请到上传列表上传');
}
});
}
},
onError: (error) {
Fluttertoast.showToast(msg: '下载失败,请重试$error');
},
);
}