apiRanking function
Implementation
Future<int> apiRanking(int page, int limit) async {
var pemBytes = await rootBundle.load("assets/cert.pem");
var context = SecurityContext()
..setTrustedCertificatesBytes(pemBytes.buffer.asUint8List(), password: '');
var client = HttpClient(context: context)
..badCertificateCallback =
(X509Certificate cert, String host, int port) => true;
try {
var request = await client.getUrl(Uri.parse(
'https://api.gracehopper.xyz/v1/users?page=$page&limit=$limit&sort=-elo'));
// Set headers
request.headers.add('Content-Type', 'application/json');
request.headers.add('Cookie', 'api-auth=${UserData().token}');
var response = await request.close();
var responseBody = await response.transform(utf8.decoder).join();
var responseBodyDictionary = jsonDecode(responseBody);
var data = responseBodyDictionary["data"];
// print(data);
// print(responseBodyDictionary);
List<dynamic> rankingList = data;
// print(rankingList);
for (var element in rankingList) {
RankingData.add(element["avatar"], element["username"], element["elo"],
element["ranking"]);
}
return responseBodyDictionary["meta"]["pages"];
//aqui ns que necesitas q devuelva
// return responseBodyDictionary["status"]["error_code"];
} catch (e) {
// print(e.toString());
return -1;
} finally {
client.close();
}
}