Added the abillity to add a server but still not being saved and added a catch to Jermys code, da es ein TimoutExeption gegeben hat #14
1 changed files with 56 additions and 7 deletions
|
@ -145,9 +145,50 @@ class _ServerListState extends State<ServerList> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _settings() {}
|
void _settings() {}
|
||||||
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
void _addServer() {
|
void _addServer() {
|
||||||
print('poop');
|
TextEditingController servername = TextEditingController();
|
||||||
|
TextEditingController uri = TextEditingController();
|
||||||
|
showDialog<String>(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text('Adding a server'),
|
||||||
|
content: SingleChildScrollView(child: Form(
|
||||||
|
key: _formKey,
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: <Widget>[
|
||||||
|
TextFormField(
|
||||||
|
controller: uri,
|
||||||
|
),
|
||||||
|
TextFormField(
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: 'Custom Name', hintText: 'Optional'),
|
||||||
|
controller: servername,
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: RaisedButton(
|
||||||
|
child: Text("Add"),
|
||||||
|
onPressed: () {
|
||||||
|
if (_formKey.currentState.validate()&&uri.text.isNotEmpty) {
|
||||||
|
_formKey.currentState.save();
|
||||||
|
Server server = Server(uri.text, uri.text);
|
||||||
|
servers.add(server);
|
||||||
|
_updateServerStatus(server);
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Widget> _createChildren() {
|
List<Widget> _createChildren() {
|
||||||
|
@ -179,7 +220,7 @@ class _ServerListState extends State<ServerList> {
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
border: Border(top: BorderSide(color: Colors.grey))),
|
border: Border(top: BorderSide(color: Colors.grey))),
|
||||||
),
|
),
|
||||||
Text('Ping: 1111'),
|
Text(servers[index].uri,textAlign: TextAlign.left,),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -247,7 +288,8 @@ class _ServerListState extends State<ServerList> {
|
||||||
return await _checkResponse(parsedUri, iterations);
|
return await _checkResponse(parsedUri, iterations);
|
||||||
} catch (ArgumentError) /* Host is a DNS name */ {
|
} catch (ArgumentError) /* Host is a DNS name */ {
|
||||||
try {
|
try {
|
||||||
var v4recs = await DnsUtils.lookupRecord(parsedUri.host, RRecordType.A);
|
var v4recs =
|
||||||
|
await DnsUtils.lookupRecord(parsedUri.host, RRecordType.A);
|
||||||
var v6recs =
|
var v6recs =
|
||||||
await DnsUtils.lookupRecord(parsedUri.host, RRecordType.AAAA);
|
await DnsUtils.lookupRecord(parsedUri.host, RRecordType.AAAA);
|
||||||
var v4 = await _getDNS(v4recs, RRecordType.A);
|
var v4 = await _getDNS(v4recs, RRecordType.A);
|
||||||
|
@ -333,10 +375,17 @@ class _ServerListState extends State<ServerList> {
|
||||||
var location = uri.path;
|
var location = uri.path;
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
Response response = await HttpUtils.getForFullResponse(
|
Response response;
|
||||||
|
try {
|
||||||
|
response = await HttpUtils.getForFullResponse(
|
||||||
scheme + "://" + host,
|
scheme + "://" + host,
|
||||||
headers: <String, String>{"Location": location})
|
headers: <String, String>{"Location": location})
|
||||||
.timeout(new Duration(seconds: 3));
|
.timeout(new Duration(seconds: 3));
|
||||||
|
} catch (error){
|
||||||
|
if (error == TimeoutException)
|
||||||
|
return ServerStatus.timeout;
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
if (response.statusCode > 199 && response.statusCode < 300) {
|
if (response.statusCode > 199 && response.statusCode < 300) {
|
||||||
return ServerStatus.ok;
|
return ServerStatus.ok;
|
||||||
} else if (response.statusCode == HttpStatus.movedPermanently ||
|
} else if (response.statusCode == HttpStatus.movedPermanently ||
|
||||||
|
|
Loading…
Reference in a new issue