]> git.cworth.org Git - lmno.games/commitdiff
Add method parsePlayers to player.dart
authorKevin Worth <kworth082@gmail.com>
Fri, 8 May 2020 12:48:10 +0000 (08:48 -0400)
committerCarl Worth <cworth@cworth.org>
Sat, 23 May 2020 13:49:00 +0000 (06:49 -0700)
This gives us a convenience method to parse the
json returned from the server into a List<Player> object

flutterempires/lib/player.dart

index 36d7ced1389db3361f0c4db527d1f9d7a47cd341..f55375c4708c003df064f3eb9153ca4df9c41fd9 100644 (file)
@@ -25,4 +25,9 @@ class Player {
       throw Exception('Failed to load player');
     }
   }
+
+  static List<Player> parsePlayers(String responseBody) {
+    final parsed = json.decode(responseBody).cast<Map<String, dynamic>>();
+    return parsed.map<Player>((json) => Player.fromJson(json)).toList();
+  }
 }