downloadContentsZip static method
Implementation
static Future<void> downloadContentsZip(String appBundle, bool usb, Function(double) setProgress,
Function(String) setError, Function(bool) setAllOk) async {
double progress = 0.0;
String error = "";
// TODO? revisar y optimizar
try {
String url = usb ? "http://127.0.0.1" : "http://192.168.2.101";
Directory? directory = await getExternalStorageDirectory();
if (directory != null) {
String zipFilePath = '${directory.path}/gvam.zip';
await Dio().download("$url:8000/get_files/$appBundle", zipFilePath,
options: Options(responseType: ResponseType.bytes), onReceiveProgress: (count, total) {
if (total != -1) {
progress = count / total;
setProgress(progress);
}
});
descompressZipByPath(zipFilePath, directory);
setAllOk(true);
Dio().post("$url:8000/increment_call_count");
} else {
throw Exception('Failed to get storage directory.');
}
} catch (e) {
error = 'Error: $e';
setError(error);
}
}