class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
+ Future<Player> futurePlayer;
+
+ @override
+ void initState() {
+ super.initState();
+ futurePlayer = Player.fetchPlayer();
+ }
+
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
),
Spacer(flex: 1),
FutureBuilder<Player>(
+ 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();
},