I am developing a flutter app using the D2 touch library to fecth dataSets now the issue i am facing is to do with sysncing metadata… i understand from the documentation this is how it is supposed to be done “d2.metadataModule().download();” but now the issue i am facing is that this is giving me an error that method does not exist…
Hi Yambanso kausiwa,
The d2.metadataModule().download() method does not exist in the D2 Touch Flutter SDK, so the error you’re seeing is expected.
Currently, metadata synchronization is done per module, not through a single global metadataModule download method. If you need a generic metadata sync, you can implement it in your own service layer based on your app structure, and internally call the download methods of the required modules.
For example, since you’re interested in DataSets, you can download them like this:
await d2.dataSetModule.dataSet
.byIds(['BfMAe6Itzgt', 'VTdjfLXXmoi'])
.download(
(progress, complete) {
print(progress.message);
}
);
The SDK supports several filters, I’ve used byIds here as an example. The download() method is available across all supported modules.
You can check the full list of available modules in the documentation under module-list.md.
After downloading the metadata, you should use the get() method to retrieve it from the local database, instead of calling download() again.
You may also find this presentation helpful: DHIS2 Flutter SDK , it explains the SDK in more detail.
If you face any issues or need further clarification, feel free to reach out.
So i have figured this out… But an issue remains with datasets… So the instance i am pulling datasets from has one dataset… So i tried to pull dataset metadata online using the fetchonline function and to my suprise when i try to print this it returned an empty array but once i looked at the network request to fetch datasets it seems that the body has the dataset i was looking for… But in my console it kept showing an empty array…
Have you tried downloading the datasets using the following approach?
await d2.dataSetModule.dataSet
.byIds(['BfMAe6Itzgt', 'VTdjfLXXmoi'])
.download((progress, complete) {
print(progress.message);
});
After the download completes, try retrieving the dataSet using the get() method.
We’re also available for a virtual meeting if that would be convenient for you.
here is my sync function
static Future sync() async {
if (_d2Instance == null) await init();
return await d2Instance!.organisationUnitModule.organisationUnit
.where(attribute: “level”, value: 5)
.download((progress, done) {
print(‘${progress.message} (${progress.percentage}%)’);
if (done) {
print(‘Download finished for ${progress.resourceName}’);
}
})
.then(() async {
await d2Instance!.dataSetModule.dataSet
.download((progress, done) {
print(‘${progress.message} (${progress.percentage}%)’);
if (done) {
print(‘Download finished for ${progress.resourceName}’);
}
})
.then(() async {
await d2Instance!.dataElementModule.dataElement
.download((progress, done) {
print(‘${progress.message} (${progress.percentage}%)’);
if (done) {
print(‘Download finished for ${progress.resourceName}’);
}
})
.then(() async {
await _d2Instance!.dataSetModule.dataSet
.byIds([“jxI7SmGpULG”])
.download((progress, done) {
print(
‘${progress.message} (${progress.percentage}%)’,
);
if (done) {
print(
‘Download finished for ${progress.resourceName}’,
);
}
});
});
});
});
}
this is called after the user has logged in online and here is a snippet of my console when downloading… here is my console I/flutter ( 5605): 0 datasets downloaded successfully (50%)
I/flutter ( 5605): Saving 0 datasets into phone database… (51%)
I/flutter ( 5605): 0 datasets successfully saved into the database (100%)
I/flutter ( 5605): Download finished for dataSets
and here is my getDatasets function
static Future getAvailableDataSets() async {
if (_d2Instance == null) await init();
try {
return await _d2Instance!.dataSetModule.dataSet.get();
} catch (e) {
print(“Error fetching DataSets: $e”);
return [
{‘error’: e.toString()},
];
}
}
and i have called it here
void getReports() async {
print(“fetch”);
await AuthService.getAvailableDataSets().then((e) {
print(e);
});
}
here is my console
I/flutter ( 5605): fetch
I/flutter ( 5605):
and the the screenshot attached is to get datasets and the response
