import 'dart:convert'; import 'package:faucethub/Backend/DebugHelper.dart'; import 'package:faucethub/Backend/brains.dart'; import 'package:http/http.dart' as http; class Hoarder{ static List GamesJson = []; static Map Settings = {}; static List FeaturedGames = []; static Future GrabInitData() async{ try { var response = (await http.post(Uri.parse('${Brain.API_ENDPOINT}get_settings.php'))); Debug.LogResponse(response.body.toString()); // Settings= jsonDecode(response.body.toString()); List jsonList = jsonDecode(response.body.toString()); jsonList.forEach((jsonItem) { Settings[jsonItem['id']] = jsonItem['value']; }); } catch (e) { Debug.LogError("Error while loading settings : $e"); } try { var response = (await http.post(Uri.parse('${Brain.API_ENDPOINT}get_games.php'))); Debug.LogResponse(response.body.toString()); GamesJson=[]; FeaturedGames = []; List games = response.body.toString().split(""); List featuredGames = Settings["featured_games"].toString().split(','); games.forEach((game) { dynamic Json = jsonDecode(game); String id = Json['id']; GamesJson.add(Json); if(featuredGames.contains(id)){ FeaturedGames.add(Json); } }); Debug.Log("Total games ${GamesJson.length} and ${FeaturedGames.length} featured"); } catch (e) { Debug.LogError("Error while loading games : $e"); } } }