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.
}
}
+ static Future<List<Player>> 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<Player> parsePlayers(String responseBody) {
final parsed = json.decode(responseBody).cast<Map<String, dynamic>>();
return parsed.map<Player>((json) => Player.fromJson(json)).toList();