download method
Implementation
@override
Future<List<DataValueSet>?> download(Function(RequestProgress, bool) callback,
{Dio? dioTestClient}) async {
callback(
RequestProgress(
resourceName: this.apiResourceName as String,
message:
'Downloading ${this.apiResourceName?.toLowerCase()} from the server....',
status: '',
percentage: 0),
false);
final response = await HttpClient.get(this.dhisUrl,
database: this.database, dioTestClient: dioTestClient);
final data = response.body;
callback(
RequestProgress(
resourceName: this.apiResourceName as String,
message:
'${this.apiResourceName?.toLowerCase()}(${this.dataSet}-${this.orgUnit}-${this.period}) downloaded successfully',
status: '',
percentage: 50),
false);
data['dirty'] = false;
this.data = DataValueSet.fromJson(data);
callback(
RequestProgress(
resourceName: this.apiResourceName as String,
message:
'Saving ${this.apiResourceName?.toLowerCase()}(${this.dataSet}-${this.orgUnit}-${this.period}) into phone database...',
status: '',
percentage: 51),
false);
await this.save();
callback(
RequestProgress(
resourceName: this.apiResourceName as String,
message:
'${this.apiResourceName?.toLowerCase()}(${this.dataSet}-${this.orgUnit}-${this.period}) successifully saved into the database',
status: '',
percentage: 100),
true);
return [this.data];
}