Fixes to persistence #29

Merged
Jeremy Kescher merged 1 commit from jeremy/0129/persistence-fixes into master 2020-01-29 13:42:27 +00:00

View file

@ -20,12 +20,10 @@ class ServerList extends StatefulWidget {
} }
class _ServerListState extends State<ServerList> { class _ServerListState extends State<ServerList> {
_ServerListState() {
_initServersFromPreferences();
}
// Currently expanded server list entry, -1 = no field is expanded // Currently expanded server list entry, -1 = no field is expanded
int selectedServer = -1; int selectedServer = -1;
List<Server> servers; List<Server> servers;
bool serversInitialised = false;
Timer timer; Timer timer;
Random rnd = new Random(); Random rnd = new Random();
@ -34,6 +32,8 @@ class _ServerListState extends State<ServerList> {
void initState() { void initState() {
super.initState(); super.initState();
_initServersFromPreferences();
timer = new Timer.periodic( timer = new Timer.periodic(
new Duration(seconds: 30), (_) => _updateAllServers()); new Duration(seconds: 30), (_) => _updateAllServers());
} }
@ -188,6 +188,7 @@ class _ServerListState extends State<ServerList> {
}); });
Navigator.of(context).pop(); Navigator.of(context).pop();
_updateServerStatus(server); _updateServerStatus(server);
_saveServersToPreferences();
} }
}, },
) )
@ -203,7 +204,8 @@ class _ServerListState extends State<ServerList> {
} }
List<Widget> _createChildren() { List<Widget> _createChildren() {
List<Widget> entries = new List<Widget>.generate(servers.length, (int index) { List<Widget> entries =
new List<Widget>.generate(servers.length, (int index) {
Widget info = Row(children: [ Widget info = Row(children: [
Expanded( Expanded(
child: Align( child: Align(
@ -326,25 +328,27 @@ class _ServerListState extends State<ServerList> {
child: info), child: info),
); );
}); });
entries.add( if (serversInitialised)
GestureDetector( entries.add(
onTap: _addServerForm, GestureDetector(
child: Container( onTap: _addServerForm,
height: 75, child: Container(
width: MediaQuery.of(context).size.width, height: 75,
margin: EdgeInsets.fromLTRB(0, 0, 0, 2), width: MediaQuery.of(context).size.width,
padding: EdgeInsets.all(10.0), margin: EdgeInsets.fromLTRB(0, 0, 0, 2),
decoration: BoxDecoration( padding: EdgeInsets.all(10.0),
color: Colors.white70, decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey, width: 2))), color: Colors.white70,
child: Icon( border:
Icons.add, Border(bottom: BorderSide(color: Colors.grey, width: 2))),
size: 42, child: Icon(
color: Colors.black, Icons.add,
size: 42,
color: Colors.black,
),
), ),
), ),
), );
);
return entries; return entries;
} }
@ -473,6 +477,7 @@ class _ServerListState extends State<ServerList> {
_updateServerStatus(server); _updateServerStatus(server);
servers.add(server); servers.add(server);
}); });
serversInitialised = true;
}); });
} }