1 import 'package:flutter/material.dart';
2 import 'package:flutterempires/player.dart';
8 class MyApp extends StatelessWidget {
9 // This widget is the root of your application.
11 Widget build(BuildContext context) {
15 // This is the theme of your application.
17 // Try running your application with "flutter run". You'll see the
18 // application has a blue toolbar. Then, without quitting the app, try
19 // changing the primarySwatch below to Colors.green and then invoke
20 // "hot reload" (press "r" in the console where you ran "flutter run",
21 // or simply save your changes to "hot reload" in a Flutter IDE).
22 // Notice that the counter didn't reset back to zero; the application
24 primarySwatch: Colors.blue,
25 // This makes the visual density adapt to the platform that you run
26 // the app on. For desktop platforms, the controls will be smaller and
27 // closer together (more dense) than on mobile platforms.
28 visualDensity: VisualDensity.adaptivePlatformDensity,
30 home: MyHomePage(title: 'Empires'),
35 class MyHomePage extends StatefulWidget {
36 MyHomePage({Key key, this.title}) : super(key: key);
38 // This widget is the home page of your application. It is stateful, meaning
39 // that it has a State object (defined below) that contains fields that affect
42 // This class is the configuration for the state. It holds the values (in this
43 // case the title) provided by the parent (in this case the App widget) and
44 // used by the build method of the State. Fields in a Widget subclass are
45 // always marked "final".
50 _MyHomePageState createState() => _MyHomePageState();
53 class _MyHomePageState extends State<MyHomePage> {
56 Future<Player> futurePlayer;
61 futurePlayer = Player.fetchFirstPlayer();
64 void _incrementCounter() {
66 // This call to setState tells the Flutter framework that something has
67 // changed in this State, which causes it to rerun the build method below
68 // so that the display can reflect the updated values. If we changed
69 // _counter without calling setState(), then the build method would not be
70 // called again, and so nothing would appear to happen.
76 Widget build(BuildContext context) {
77 // This method is rerun every time setState is called, for instance as done
78 // by the _incrementCounter method above.
80 // The Flutter framework has been optimized to make rerunning build methods
81 // fast, so that you can just rebuild anything that needs updating rather
82 // than having to individually change instances of widgets.
85 // Here we take the value from the MyHomePage object that was created by
86 // the App.build method, and use it to set our appbar title.
87 title: Text(widget.title),
90 margin: const EdgeInsets.only(left: 20.0, right: 20.0),
93 mainAxisAlignment: MainAxisAlignment.center,
94 crossAxisAlignment: CrossAxisAlignment.start,
99 style: Theme.of(context).textTheme.headline4,
102 decoration: InputDecoration(
103 hintText: 'Enter your (real) name',
109 style: Theme.of(context).textTheme.headline4,
112 decoration: InputDecoration(
113 hintText: 'Enter your empire character name',
117 FutureBuilder<Player>(
118 future: futurePlayer,
119 builder: (context, snapshot) {
120 if (snapshot.hasData) {
121 return Text(snapshot.data.name);
122 } else if (snapshot.hasError) {
123 return Text("${snapshot.error}");
125 // By default, show a loading spinner.
126 return CircularProgressIndicator();
134 floatingActionButton: FloatingActionButton(
135 onPressed: _incrementCounter,
136 tooltip: 'Increment',
137 child: Icon(Icons.add),
138 ), // This trailing comma makes auto-formatting nicer for build methods.