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