X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=flutterempires%2Flib%2Fmain.dart;h=c92508bebecda377b6791f2f163cb0fad09d7f57;hb=5dc18c0cd3f7852b9185260a2bffa7f23125f0c4;hp=816b13eab8ad4082d493bcb9b901e84bdc946c53;hpb=6382d12f524932ff1d26957e86428047714b128c;p=lmno.games diff --git a/flutterempires/lib/main.dart b/flutterempires/lib/main.dart index 816b13e..c92508b 100644 --- a/flutterempires/lib/main.dart +++ b/flutterempires/lib/main.dart @@ -51,24 +51,20 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { - int _counter = 0; - Future futurePlayer; + Future> allPlayers; @override void initState() { super.initState(); - futurePlayer = Player.fetchPlayer(); + futurePlayer = Player.fetchFirstPlayer(); + 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(); }); } @@ -88,51 +84,26 @@ class _MyHomePageState extends State { ), body: new Container( margin: const EdgeInsets.only(left: 20.0, right: 20.0), - child : Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Spacer(flex: 10), - 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( - future: futurePlayer, - builder: (context, snapshot) { - if (snapshot.hasData) { - return Text(snapshot.data.name); - } else if (snapshot.hasError) { - return Text("${snapshot.error}"); - } - // By default, show a loading spinner. - return CircularProgressIndicator(); - }, - ), - Spacer(flex: 10), - ], - ), + child: Center( + child: FutureBuilder>( + 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.