resolveData method
Implementation
Future<void> resolveData() async {
if (json != null) {
return;
} else if (base64 != null) {
json = jsonDecode(utf8.decode(base64Decode(addPaddingToBase64(base64!))));
} else if (links != null && links!.isNotEmpty) {
if (hash == null) throw Exception('If links are used hash must be given');
for (var link in links!) {
try {
var client = await HttpClient()
.getUrl(Uri.parse(link))
.timeout(Duration(seconds: 15));
var res = await client.close();
if (res.statusCode == 200) {
var contents = StringBuffer();
await for (var data in res.transform(utf8.decoder)) {
contents.write(data);
}
json = jsonDecode(contents.toString());
break;
}
} catch (e) {
throw Exception('Cant load link data for $link');
}
}
if (json == null) throw Exception('No data found');
} else {
throw Exception('No data');
}
}