From: Kevin Worth Date: Fri, 8 May 2020 12:48:10 +0000 (-0400) Subject: Add method parsePlayers to player.dart X-Git-Url: https://git.cworth.org/git?p=lmno.games;a=commitdiff_plain;h=c366b1a7794cf16da41d8a316188d61bb738d6b5 Add method parsePlayers to player.dart This gives us a convenience method to parse the json returned from the server into a List object --- diff --git a/flutterempires/lib/player.dart b/flutterempires/lib/player.dart index 36d7ced..f55375c 100644 --- a/flutterempires/lib/player.dart +++ b/flutterempires/lib/player.dart @@ -25,4 +25,9 @@ class Player { throw Exception('Failed to load player'); } } + + static List parsePlayers(String responseBody) { + final parsed = json.decode(responseBody).cast>(); + return parsed.map((json) => Player.fromJson(json)).toList(); + } }