]> git.cworth.org Git - lmno.games/commitdiff
Add a FutureBuilder widget to hold a fetched player
authorKevin Worth <kworth082@gmail.com>
Sun, 3 May 2020 19:31:41 +0000 (15:31 -0400)
committerCarl Worth <cworth@cworth.org>
Sat, 23 May 2020 13:49:00 +0000 (06:49 -0700)
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.

flutterempires/lib/main.dart

index 92cda02bbd2790a997d0da757c23c00533d2644a..7bb1c7deb4d75311e97d82f1a959cde946f122f2 100644 (file)
@@ -1,4 +1,5 @@
 import 'package:flutter/material.dart';
+import 'package:flutterempires/player.dart';
 
 void main() {
   runApp(MyApp());
@@ -94,7 +95,7 @@ class _MyHomePageState extends State<MyHomePage> {
                   hintText: 'Enter your (real) name',
                 ),
               ),
-              Spacer(),
+              Spacer(flex: 1),
               Text(
                 'Character:',
                 style: Theme.of(context).textTheme.headline4,
@@ -104,6 +105,13 @@ class _MyHomePageState extends State<MyHomePage> {
                   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),
             ],
           ),