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