Rather than doing a fetch within this build method (which gets called repeatedly),
we use a FutureBuilder to show a spinner until the player has finished being
fetched asynchronously.
import 'package:flutter/material.dart';
+import 'package:flutterempires/player.dart';
void main() {
runApp(MyApp());
hintText: 'Enter your (real) name',
),
),
- Spacer(),
+ Spacer(flex: 1),
Text(
'Character:',
style: Theme.of(context).textTheme.headline4,
hintText: 'Enter your empire character name',
),
),
+ Spacer(flex: 1),
+ FutureBuilder<Player>(
+ builder: (context, snapshot) {
+ // By default, show a loading spinner.
+ return CircularProgressIndicator();
+ },
+ ),
Spacer(flex: 10),
],
),