]> git.cworth.org Git - lmno.games/blobdiff - flutterempires/lib/main.dart
Rip out column and just show player list view
[lmno.games] / flutterempires / lib / main.dart
index 92cda02bbd2790a997d0da757c23c00533d2644a..ae5441fc947d4fcbffe9008a0ae71f018c8cf0b1 100644 (file)
@@ -1,4 +1,5 @@
 import 'package:flutter/material.dart';
+import 'package:flutterempires/player.dart';
 
 void main() {
   runApp(MyApp());
@@ -50,16 +51,19 @@ class MyHomePage extends StatefulWidget {
 }
 
 class _MyHomePageState extends State<MyHomePage> {
-  int _counter = 0;
+  Future<Player> futurePlayer;
+  Future<List<Player>> allPlayers;
 
-  void _incrementCounter() {
+  @override
+  void initState() {
+    super.initState();
+    futurePlayer = Player.fetchFirstPlayer();
+    allPlayers = Player.fetchAllPlayers();
+  }
+
+  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
     });
   }
 
@@ -79,38 +83,26 @@ class _MyHomePageState extends State<MyHomePage> {
       ),
       body: new Container(
         margin: const EdgeInsets.only(left: 20.0, right: 20.0),
-        child : Center(
-          child: Column(
-            mainAxisAlignment: MainAxisAlignment.center,
-            crossAxisAlignment: CrossAxisAlignment.start,
-            children: <Widget>[
-              Spacer(flex: 10),
-              Text(
-                'Name:',
-                style: Theme.of(context).textTheme.headline4,
-              ),
-              TextField(
-                decoration: InputDecoration(
-                  hintText: 'Enter your (real) name',
-                ),
-              ),
-              Spacer(),
-              Text(
-                'Character:',
-                style: Theme.of(context).textTheme.headline4,
-              ),
-              TextField(
-                decoration: InputDecoration(
-                  hintText: 'Enter your empire character name',
-                ),
-              ),
-              Spacer(flex: 10),
-            ],
-          ),
+        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();
+              }),
         ),
       ),
       floatingActionButton: FloatingActionButton(
-        onPressed: _incrementCounter,
+        onPressed: onPressPlusButton,
         tooltip: 'Increment',
         child: Icon(Icons.add),
       ), // This trailing comma makes auto-formatting nicer for build methods.