From 0f4784ad53479b109d186464f54850b73fe402f7 Mon Sep 17 00:00:00 2001 From: Kevin Worth Date: Fri, 8 May 2020 08:53:45 -0400 Subject: [PATCH] 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. --- flutterempires/lib/player.dart | 10 ++++++++++ 1 file changed, 10 insertions(+) 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(); -- 2.43.0