fetchOnline method
Future<List<T>>
fetchOnline(
{ - Dio? dioTestClient,
})
Implementation
Future<List<T>> fetchOnline({Dio? dioTestClient}) async {
try {
final dhisUrl = await this.dhisUrl();
final response = await HttpClient.get(dhisUrl,
database: this.database, dioTestClient: dioTestClient);
List data = response.body != null
? response.body[this.apiResourceName]?.toList() ?? []
: [];
return data.map((dataItem) {
dataItem['dirty'] = false;
dataItem['synced'] = true;
ClassMirror classMirror =
AnnotationReflectable.reflectType(T) as ClassMirror;
var x = classMirror.newInstance('fromJson', [dataItem]) as T;
return x;
}).toList();
} catch (e) {
print(e);
return [];
}
}