]> 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 ae5441fc947d4fcbffe9008a0ae71f018c8cf0b1..89867ec99bb629883d56040ca5defdd9d28a1d33 100644 (file)
@@ -64,6 +64,7 @@ class _MyHomePageState extends State<MyHomePage> {
   void onPressPlusButton() {
     setState(() {
       // Probably use this to POST player name and character
+      allPlayers = Player.fetchAllPlayers();
     });
   }
 
@@ -84,21 +85,80 @@ class _MyHomePageState extends State<MyHomePage> {
       body: new Container(
         margin: const EdgeInsets.only(left: 20.0, right: 20.0),
         child: Center(
-          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();
-              }),
+          child: Column(
+            mainAxisAlignment: MainAxisAlignment.center,
+            crossAxisAlignment: CrossAxisAlignment.start,
+            children: <Widget>[
+              Spacer(flex: 1),
+              Text(
+                'Name:',
+                style: Theme.of(context).textTheme.headline4,
+              ),
+              TextField(
+                decoration: InputDecoration(
+                  hintText: 'Enter your (real) name',
+                ),
+              ),
+              Spacer(flex: 1),
+              Text(
+                'Character:',
+                style: Theme.of(context).textTheme.headline4,
+              ),
+              TextField(
+                decoration: InputDecoration(
+                  hintText: 'Enter your empire character name',
+                ),
+              ),
+              Spacer(flex: 1),
+              FutureBuilder<Player>(
+                future: futurePlayer,
+                builder: (context, snapshot) {
+                  if (snapshot.hasData) {
+                    return Text(snapshot.data.name);
+                  } 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();
+                },
+              ),
+              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();
+                    }),
+              )
+            ],
+          ),
         ),
       ),
       floatingActionButton: FloatingActionButton(