]> git.cworth.org Git - lmno.games/blobdiff - flutterempires/lib/main.dart
Show text if player list returns empty
[lmno.games] / flutterempires / lib / main.dart
index a252d45ad6b209e8776a23eb7df1fba938bffe90..89867ec99bb629883d56040ca5defdd9d28a1d33 100644 (file)
@@ -134,24 +134,31 @@ class _MyHomePageState extends State<MyHomePage> {
                   return CircularProgressIndicator();
                 },
               ),
-              Spacer(flex: 10),
+              Expanded(
+                flex: 10,
+                child: FutureBuilder<List<Player>>(
+                    future: allPlayers,
+                    builder: (context, snapshot) {
+                      if (snapshot.hasData) {
+                        if (snapshot.data.length == 0) {
+                          return Text('No players yet');
+                        } else {
+                          return ListView.builder(
+                              itemCount: snapshot.data.length,
+                              itemBuilder: (context, index) {
+                                return ListTile(
+                                    title: Text(
+                                        snapshot.data[index].name.toString()));
+                              });
+                        }
+                      } else if (snapshot.hasError) {
+                        return Text("${snapshot.error}");
+                      }
+                      return CircularProgressIndicator();
+                    }),
+              )
             ],
           ),
-          child: FutureBuilder<List<Player>>(
-              future: allPlayers,
-              builder: (context, snapshot) {
-                if (snapshot.hasData) {
-                  return ListView.builder(
-                      itemCount: snapshot.data.length,
-                      itemBuilder: (context, index) {
-                        return ListTile(
-                            title: Text(snapshot.data[index].name.toString()));
-                      });
-                } else if (snapshot.hasError) {
-                  return Text("${snapshot.error}");
-                }
-                return CircularProgressIndicator();
-              }),
         ),
       ),
       floatingActionButton: FloatingActionButton(