getSpin method
dynamic
getSpin({})
Implementation
getSpin({
String forceUrl =
"https://miracocopepsi.com/admin/mayur/data_darsh/reward.json",
String listKey = "rewards",
int? checkIndex = 0,
String checkKey = "isspin",
required Function(List spins) onCompleted,
required Function(String error) onError,
}) async {
try {
Response response = await Dio().get(forceUrl);
if (checkIndex != null) {
List temp = [];
List coinList =
(listKey.isEmpty ? response.data : response.data[listKey]) ?? [];
for (int i = 0; i < coinList.length; i++) {
if (coinList[i][checkKey] == checkIndex) {
temp.add(coinList[i]);
}
}
onCompleted(
temp,
);
}
onCompleted(
listKey.isEmpty ? response.data : response.data[listKey] ?? [],
);
} on DioError catch (e) {
onError(e.message ?? "");
} catch (e) {
onError(e.toString());
}
}