update serverlist #10

Merged
Hugo Bayer merged 1 commit from Hugo/11-18-28-01-2020/updateServerlist into master 2020-01-28 10:19:52 +00:00

View file

@ -27,9 +27,7 @@ class ServerList extends StatefulWidget {
}
class _ServerListState extends State<ServerList> {
List<Server> server = [
List<Server> servers = [
new Server(
"example.com",
"http://example.com",
@ -51,27 +49,34 @@ class _ServerListState extends State<ServerList> {
Timer timer;
Random rnd = new Random();
@override
void initState() {
super.initState();
_ServerListState() {
_updateAllServers();
timer = new Timer.periodic(new Duration(seconds: 5), (timer) {
server.forEach(_updateServerStatus);
_updateAllServers();
});
}
void _updateServerStatus(Server server) {
Future<void> _updateAllServers() async {
servers.forEach(_updateServerStatus);
}
void _updateServerStatus(Server s) async {
checkStatus(s.uri).then((value) {
setState(() {
server.status =
ServerStatus.values[rnd.nextInt(ServerStatus.values.length - 1) + 1];
checkStatus(s.uri).then((value){
s.status=value;
});
});
});
}
void _updateUI() {
setState(() {
});
setState(() {});
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
@ -116,15 +121,11 @@ class _ServerListState extends State<ServerList> {
);
}
List<Widget> _createChildren() {
return new List<Widget>.generate(server.length, (int index) {
return new List<Widget>.generate(servers.length, (int index) {
return Container(
height: 75,
width: MediaQuery
.of(context)
.size
.width,
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.all(2.0),
padding: EdgeInsets.all(10.0),
decoration: BoxDecoration(
@ -138,7 +139,7 @@ class _ServerListState extends State<ServerList> {
child: Align(
alignment: Alignment.centerLeft,
child: Text(
server[index].displayName,
servers[index].displayName,
style: TextStyle(fontSize: 24),
),
),
@ -147,7 +148,7 @@ class _ServerListState extends State<ServerList> {
width: 75,
child: Align(
alignment: Alignment.center,
child: _generateIcon(server[index]),
child: _generateIcon(servers[index]),
// child: Text(
// status[index],
// style: TextStyle(fontSize: 24),
@ -167,15 +168,13 @@ class _ServerListState extends State<ServerList> {
print("The URI was invalid, returning DNS_ERROR");
return ServerStatus.dnserror;
}
if (parsedUri.isScheme("http") || parsedUri.isScheme("http")) {
}
if (parsedUri.isScheme("http") || parsedUri.isScheme("http")) {}
try {
InternetAddress ia = InternetAddress(parsedUri.host);
parsedUri.scheme
//parsedUri.scheme
} catch (ArgumentError) {
List<RRecord> record = await DnsUtils.lookupRecord(
parsedUri.host, RRecordType.ANY);
List<RRecord> record =
await DnsUtils.lookupRecord(parsedUri.host, RRecordType.ANY);
}
return ServerStatus.responding;