Check status method #9

Merged
Jeremy Kescher merged 2 commits from jeremy/0128/checkstatus into master 2020-01-28 09:22:34 +00:00
3 changed files with 42 additions and 19 deletions

View File

@ -1,13 +1,12 @@
enum ServerStatus{
unknown, timeout, responding, dnserror
}
enum ServerStatus { unknown, timeout, responding, dnserror }
class Server {
String uri;
String displayName;
ServerStatus status = ServerStatus.unknown;
Server(this.displayName,this.uri,);
}
Server(
this.displayName,
this.uri,
);
}

View File

@ -1,9 +1,13 @@
import 'dart:async';
import 'dart:math';
import 'dart:io';
import 'package:basic_utils/basic_utils.dart';
import 'package:flutter/material.dart';
import 'package:server_pinger/server.dart';
import 'server.dart';
class ServerList extends StatefulWidget {
ServerList({Key key, this.title}) : super(key: key);
@ -48,16 +52,16 @@ class _ServerListState extends State<ServerList> {
Random rnd = new Random();
_ServerListState(){
timer = new Timer.periodic(new Duration(seconds: 5), (timer){
_ServerListState() {
timer = new Timer.periodic(new Duration(seconds: 5), (timer) {
server.forEach(_updateServerStatus);
});
}
void _updateServerStatus(Server server){
void _updateServerStatus(Server server) {
setState(() {
server.status=ServerStatus.values[rnd.nextInt(ServerStatus.values.length-1)+1];
server.status =
ServerStatus.values[rnd.nextInt(ServerStatus.values.length - 1) + 1];
});
}
@ -68,7 +72,6 @@ class _ServerListState extends State<ServerList> {
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
@ -114,9 +117,7 @@ class _ServerListState extends State<ServerList> {
}
List<Widget> _createChildren() {
List<String> status = ["ON", "OFF?", "ON", "ON"];
return new List<Widget>.generate(server.length, (int index) {
return Container(
height: 75,
@ -158,13 +159,35 @@ class _ServerListState extends State<ServerList> {
});
}
static Future<ServerStatus> checkStatus(String uri) async {
Uri parsedUri;
try {
parsedUri = Uri.parse(uri);
} catch (FormatException) {
print("The URI was invalid, returning DNS_ERROR");
return ServerStatus.dnserror;
}
if (parsedUri.isScheme("http") || parsedUri.isScheme("http")) {
}
try {
InternetAddress ia = InternetAddress(parsedUri.host);
parsedUri.scheme
} catch (ArgumentError) {
List<RRecord> record = await DnsUtils.lookupRecord(
parsedUri.host, RRecordType.ANY);
}
return ServerStatus.responding;
}
Icon _generateIcon(Server server) {
if (server.status == ServerStatus.unknown)
return new Icon(
Icons.check_box_outline_blank,
color: Colors.yellow,
);
else if(server.status == ServerStatus.responding)
else if (server.status == ServerStatus.responding)
return new Icon(
Icons.check_box,
color: Colors.green,
@ -175,5 +198,4 @@ class _ServerListState extends State<ServerList> {
color: Colors.red,
);
}
}
}

View File

@ -22,7 +22,9 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
cupertino_icons: ^0.1.3
basic_utils: ^2.4.8
dev_dependencies:
flutter_test: