From 67de301bfa5d4630232a48ff8d2e8c5598ade89c Mon Sep 17 00:00:00 2001 From: Jeremy Kescher Date: Tue, 28 Jan 2020 10:18:14 +0100 Subject: [PATCH 1/2] Add basic_utils dependency --- pubspec.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 0ccd8de..6b82c4d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: -- 2.47.1 From f2c865c37d95a6330604d471e33bfad0f281e677 Mon Sep 17 00:00:00 2001 From: Jeremy Kescher Date: Tue, 28 Jan 2020 10:18:45 +0100 Subject: [PATCH 2/2] WIP checkStatus() --- lib/server.dart | 13 ++++++------- lib/serverlist.dart | 44 +++++++++++++++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/lib/server.dart b/lib/server.dart index 6b42b2e..48060cc 100644 --- a/lib/server.dart +++ b/lib/server.dart @@ -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,); - - -} \ No newline at end of file + Server( + this.displayName, + this.uri, + ); +} diff --git a/lib/serverlist.dart b/lib/serverlist.dart index 1758cb6..b5bc1e8 100644 --- a/lib/serverlist.dart +++ b/lib/serverlist.dart @@ -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 { 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 { } - @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 { } - List _createChildren() { - List status = ["ON", "OFF?", "ON", "ON"]; return new List.generate(server.length, (int index) { return Container( height: 75, @@ -158,13 +159,35 @@ class _ServerListState extends State { }); } + static Future 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 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 { color: Colors.red, ); } - -} +} \ No newline at end of file -- 2.47.1