]> git.cworth.org Git - lmno.games/commitdiff
Display total number of players
authorKevin Worth <kworth082@gmail.com>
Fri, 8 May 2020 12:58:03 +0000 (08:58 -0400)
committerCarl Worth <cworth@cworth.org>
Sat, 23 May 2020 13:49:00 +0000 (06:49 -0700)
Setting up a new widget to display the list of players, but for the
time being (for simplicity's sake) it's just displaying the size of the
returned list of players.

flutterempires/lib/main.dart

index e313be10cb04ba71750ab650ab2a589a0cd48b8f..0d574045a4f04c4a3115c65adc0d9e4abaffec60 100644 (file)
@@ -54,11 +54,13 @@ class _MyHomePageState extends State<MyHomePage> {
   int _counter = 0;
 
   Future<Player> futurePlayer;
+  Future<List<Player>> allPlayers;
 
   @override
   void initState() {
     super.initState();
     futurePlayer = Player.fetchFirstPlayer();
+    allPlayers = Player.fetchAllPlayers();
   }
 
   void _incrementCounter() {
@@ -122,6 +124,18 @@ class _MyHomePageState extends State<MyHomePage> {
                   } else if (snapshot.hasError) {
                     return Text("${snapshot.error}");
                   }
+                  return CircularProgressIndicator();
+                },
+              ),
+              Spacer(flex: 1),
+              FutureBuilder<List<Player>>(
+                future: allPlayers,
+                builder: (context, snapshot) {
+                  if (snapshot.hasData) {
+                    return Text(snapshot.data.length.toString());
+                  } else if (snapshot.hasError) {
+                    return Text("${snapshot.error}");
+                  }
                   // By default, show a loading spinner.
                   return CircularProgressIndicator();
                 },