]> git.cworth.org Git - lmno.games/commitdiff
Add fetchAllPlayers method
authorKevin Worth <kworth082@gmail.com>
Fri, 8 May 2020 12:53:45 +0000 (08:53 -0400)
committerCarl Worth <cworth@cworth.org>
Sat, 23 May 2020 13:49:00 +0000 (06:49 -0700)
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

index 809ea13bb442506df1a1c2182b3a495fd2ce04c0..aa87c8411d844dba694e015d19bbcd90a72fe2e5 100644 (file)
@@ -26,6 +26,16 @@ class 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();