X-Git-Url: https://git.cworth.org/git?p=lmno.games;a=blobdiff_plain;f=flutterempires%2Flib%2Fmain.dart;h=5a7981b19a1c0a76d6ea823c610ef894222658ef;hp=92cda02bbd2790a997d0da757c23c00533d2644a;hb=77a289b40313bf31cdc179184d2fdb063c60844c;hpb=6aafa97151b1ba8c7f8263c971a7614277a3ec89 diff --git a/flutterempires/lib/main.dart b/flutterempires/lib/main.dart index 92cda02..5a7981b 100644 --- a/flutterempires/lib/main.dart +++ b/flutterempires/lib/main.dart @@ -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 { - int _counter = 0; + Future futurePlayer; + Future> 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,12 +83,12 @@ 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, children: [ - Spacer(flex: 10), + Spacer(flex: 1), Text( 'Name:', style: Theme.of(context).textTheme.headline4, @@ -94,7 +98,7 @@ class _MyHomePageState extends State { hintText: 'Enter your (real) name', ), ), - Spacer(), + Spacer(flex: 1), Text( 'Character:', style: Theme.of(context).textTheme.headline4, @@ -104,13 +108,38 @@ class _MyHomePageState extends State { 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}"); + } + return CircularProgressIndicator(); + }, + ), + Spacer(flex: 1), + FutureBuilder>( + 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), ], ), ), ), floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, + onPressed: onPressPlusButton, tooltip: 'Increment', child: Icon(Icons.add), ), // This trailing comma makes auto-formatting nicer for build methods.