X-Git-Url: https://git.cworth.org/git?p=lmno.games;a=blobdiff_plain;f=flutterempires%2Flib%2Fmain.dart;h=89867ec99bb629883d56040ca5defdd9d28a1d33;hp=7d972a3a44b1655b0fa9f88aa02337da3cec226f;hb=8052a68188149faed5405180b20245d8b686b07a;hpb=1b36d8803dfcb9505acc8967abe323794ba2e571 diff --git a/flutterempires/lib/main.dart b/flutterempires/lib/main.dart index 7d972a3..89867ec 100644 --- a/flutterempires/lib/main.dart +++ b/flutterempires/lib/main.dart @@ -51,8 +51,6 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { - int _counter = 0; - Future futurePlayer; Future> allPlayers; @@ -63,14 +61,10 @@ class _MyHomePageState extends State { 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,7 +84,7 @@ class _MyHomePageState extends State { ), 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, @@ -140,13 +134,35 @@ class _MyHomePageState extends State { return CircularProgressIndicator(); }, ), - Spacer(flex: 10), + Expanded( + flex: 10, + child: FutureBuilder>( + 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.