From: Kevin Worth Date: Fri, 8 May 2020 12:53:45 +0000 (-0400) Subject: Add fetchAllPlayers method X-Git-Url: https://git.cworth.org/git?p=lmno.games;a=commitdiff_plain;h=0f4784ad53479b109d186464f54850b73fe402f7 Add fetchAllPlayers method This method is really the one we've needed all along and so now we can display the list of players instead of just the first player. --- diff --git a/flutterempires/lib/player.dart b/flutterempires/lib/player.dart index 809ea13..aa87c84 100644 --- a/flutterempires/lib/player.dart +++ b/flutterempires/lib/player.dart @@ -26,6 +26,16 @@ class Player { } } + static Future> fetchAllPlayers() async { + final response = await http.get('https://families.cworth.org/api/players'); + + if (response.statusCode == 200) { + return parsePlayers(response.body); + } else { + throw Exception('Failed to load players'); + } + } + static List parsePlayers(String responseBody) { final parsed = json.decode(responseBody).cast>(); return parsed.map((json) => Player.fromJson(json)).toList();