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,6 +328,7 @@ class _ServerListState extends State<ServerList> {
child: info), child: info),
); );
}); });
if (serversInitialised)
entries.add( entries.add(
GestureDetector( GestureDetector(
onTap: _addServerForm, onTap: _addServerForm,
@ -336,7 +339,8 @@ class _ServerListState extends State<ServerList> {
padding: EdgeInsets.all(10.0), padding: EdgeInsets.all(10.0),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white70, color: Colors.white70,
border: Border(bottom: BorderSide(color: Colors.grey, width: 2))), border:
Border(bottom: BorderSide(color: Colors.grey, width: 2))),
child: Icon( child: Icon(
Icons.add, Icons.add,
size: 42, size: 42,
@ -473,6 +477,7 @@ class _ServerListState extends State<ServerList> {
_updateServerStatus(server); _updateServerStatus(server);
servers.add(server); servers.add(server);
}); });
serversInitialised = true;
}); });
} }