download method
dynamic
download({
- required dynamic callback(
- List<
RequestProgress> ?, - bool,
- dynamic
- List<
- Database? database,
Implementation
download(
{required Function(List<RequestProgress>?, bool, dynamic) callback,
Database? database}) async {
if (!this.metadataSyncInProgress) {
this.metadataSyncInProgress = true;
try {
List<QueryResource> queryResources = QueryResource.getQueryResources(
currentUser: null, database: database);
List<RequestProgress> requestProgresses =
queryResources.map((QueryResource queryResource) {
return RequestProgress(
resourceName: queryResource.name,
message:
'Downloading ${queryResource.name.toUpperCase()} from the server',
status: '',
percentage: 0);
}).toList();
final queue = Queue(parallel: 2);
queryResources.forEach((queryResource) {
queue.add(() => HttpClient.get(queryResource.dhisUrl));
});
await queue.onComplete;
callback(requestProgresses, false, null);
} catch (e) {
callback(null, false, e);
}
}
}