Show text if player list returns empty
authorKevin Worth <kworth082@gmail.com>
Tue, 12 May 2020 03:13:11 +0000 (23:13 -0400)
committerCarl Worth <cworth@cworth.org>
Sat, 23 May 2020 13:49:00 +0000 (06:49 -0700)
Better to show "No players yet" than nothing when the server returns an
empty list.

flutterempires/lib/main.dart

index 3cb887278f5c497a3ebd9fd939baa7a7475983f8..89867ec99bb629883d56040ca5defdd9d28a1d33 100644 (file)
@@ -140,13 +140,17 @@ class _MyHomePageState extends State<MyHomePage> {
                     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()));
-                            });
+                        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}");
                       }