]> git.cworth.org Git - lmno.games/blobdiff - flutterempires/lib/main.dart
Prepare directories for merge into lmno.games
[lmno.games] / flutterempires / lib / main.dart
index 0d574045a4f04c4a3115c65adc0d9e4abaffec60..64d8bf057591cad6e02f85b9c21844bef19e0eb3 100644 (file)
@@ -51,8 +51,6 @@ class MyHomePage extends StatefulWidget {
 }
 
 class _MyHomePageState extends State<MyHomePage> {
-  int _counter = 0;
-
   Future<Player> futurePlayer;
   Future<List<Player>> allPlayers;
 
@@ -63,14 +61,10 @@ class _MyHomePageState extends State<MyHomePage> {
     allPlayers = Player.fetchAllPlayers();
   }
 
-  void _incrementCounter() {
+  void onPressPlusButton() {
     setState(() {
-      // This call to setState tells the Flutter framework that something has
-      // changed in this State, which causes it to rerun the build method below
-      // so that the display can reflect the updated values. If we changed
-      // _counter without calling setState(), then the build method would not be
-      // called again, and so nothing would appear to happen.
-      _counter++;
+      // Probably use this to POST player name and character
+      allPlayers = Player.fetchAllPlayers();
     });
   }
 
@@ -90,12 +84,12 @@ class _MyHomePageState extends State<MyHomePage> {
       ),
       body: new Container(
         margin: const EdgeInsets.only(left: 20.0, right: 20.0),
-        child : Center(
+        child: Center(
           child: Column(
             mainAxisAlignment: MainAxisAlignment.center,
             crossAxisAlignment: CrossAxisAlignment.start,
             children: <Widget>[
-              Spacer(flex: 10),
+              Spacer(flex: 1),
               Text(
                 'Name:',
                 style: Theme.of(context).textTheme.headline4,
@@ -116,37 +110,35 @@ class _MyHomePageState extends State<MyHomePage> {
                 ),
               ),
               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();
-                },
-              ),
-              Spacer(flex: 10),
+              Expanded(
+                flex: 20,
+                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(
-        onPressed: _incrementCounter,
+        onPressed: onPressPlusButton,
         tooltip: 'Increment',
         child: Icon(Icons.add),
       ), // This trailing comma makes auto-formatting nicer for build methods.