When creating a server you now have to choose from http:// or https:// and you now see what the icon means #33
2 changed files with 106 additions and 20 deletions
43
lib/protocol_dropdown.dart
Normal file
43
lib/protocol_dropdown.dart
Normal file
|
@ -0,0 +1,43 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class ProtocolDropdown extends StatefulWidget {
|
||||
ProtocolDropdown({Key key,this.protocol='https://'}) : super(key: key);
|
||||
|
||||
final String protocol;
|
||||
|
||||
_ProtocolDropdownState state;
|
||||
|
||||
@override
|
||||
_ProtocolDropdownState createState(){
|
||||
state = _ProtocolDropdownState(protocol);
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
class _ProtocolDropdownState extends State<ProtocolDropdown> {
|
||||
|
||||
_ProtocolDropdownState(this.protocol);
|
||||
String protocol = 'https://';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DropdownButton<String>(
|
||||
value: protocol,
|
||||
iconSize: 0,
|
||||
onChanged: (String newValue) {
|
||||
setState(() {
|
||||
protocol = newValue;
|
||||
});
|
||||
},
|
||||
items: <String>['https://','http://']
|
||||
.map<DropdownMenuItem<String>>((String value) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: value,
|
||||
child: Text(value),
|
||||
);
|
||||
})
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -5,6 +5,7 @@ import 'dart:math';
|
|||
|
||||
import 'package:basic_utils/basic_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:server_pinger/protocol_dropdown.dart';
|
||||
import 'package:server_pinger/server.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
|
@ -71,6 +72,7 @@ class _ServerListState extends State<ServerList> {
|
|||
void _addServerForm() {
|
||||
TextEditingController serverName = TextEditingController();
|
||||
TextEditingController uri = TextEditingController();
|
||||
ProtocolDropdown dropdown = ProtocolDropdown();
|
||||
showDialog<String>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
|
@ -89,12 +91,18 @@ class _ServerListState extends State<ServerList> {
|
|||
),
|
||||
controller: serverName,
|
||||
),
|
||||
TextFormField(
|
||||
controller: uri,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'URL',
|
||||
hintText: 'https://example.com',
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
dropdown,
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
controller: uri,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'example.com',
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
|
@ -104,7 +112,8 @@ class _ServerListState extends State<ServerList> {
|
|||
if (_formKey.currentState.validate() &&
|
||||
uri.text.isNotEmpty) {
|
||||
_formKey.currentState.save();
|
||||
_addServer(serverName.text, uri.text);
|
||||
_addServer(serverName.text,
|
||||
dropdown.state.protocol + uri.text);
|
||||
}
|
||||
},
|
||||
),
|
||||
|
@ -134,9 +143,13 @@ class _ServerListState extends State<ServerList> {
|
|||
}
|
||||
|
||||
void _modifyServerForm(Server server) {
|
||||
TextEditingController servername =
|
||||
ProtocolDropdown dropdown = ProtocolDropdown(
|
||||
protocol: server.uri.split('//')[0] + '//',
|
||||
);
|
||||
TextEditingController serverName =
|
||||
TextEditingController(text: server.displayName);
|
||||
TextEditingController uri = TextEditingController(text: server.uri);
|
||||
TextEditingController uri = TextEditingController(
|
||||
text: server.uri.substring(server.uri.indexOf('//') + 2));
|
||||
showDialog<String>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
|
@ -152,13 +165,17 @@ class _ServerListState extends State<ServerList> {
|
|||
decoration: InputDecoration(
|
||||
labelText: 'Display name',
|
||||
),
|
||||
controller: servername,
|
||||
controller: serverName,
|
||||
),
|
||||
TextFormField(
|
||||
controller: uri,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'URL',
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
dropdown,
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
controller: uri,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
|
@ -179,8 +196,8 @@ class _ServerListState extends State<ServerList> {
|
|||
if (_formKey.currentState.validate()) {
|
||||
_formKey.currentState.save();
|
||||
setState(() {
|
||||
server.displayName = servername.text;
|
||||
server.uri = uri.text;
|
||||
server.displayName = serverName.text;
|
||||
server.uri = dropdown.state.protocol + uri.text;
|
||||
});
|
||||
Navigator.of(context).pop();
|
||||
_updateServerStatus(server);
|
||||
|
@ -232,12 +249,19 @@ class _ServerListState extends State<ServerList> {
|
|||
border: Border(top: BorderSide(color: Colors.grey))),
|
||||
padding: EdgeInsets.fromLTRB(0, 0, 0, 5),
|
||||
),
|
||||
Align(
|
||||
child: Text(_getStatusString(servers[index].status)),
|
||||
alignment: Alignment.centerLeft,
|
||||
),
|
||||
Row(children: [
|
||||
Expanded(
|
||||
child: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: Text(
|
||||
_truncateURI(servers[index].uri),
|
||||
textAlign: TextAlign.left,
|
||||
)),
|
||||
_truncateURI(servers[index].uri),
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
alignment: Alignment.center,
|
||||
icon: Icon(
|
||||
|
@ -496,4 +520,23 @@ class _ServerListState extends State<ServerList> {
|
|||
.then((set) {});
|
||||
});
|
||||
}
|
||||
|
||||
String _getStatusString(ServerStatus status) {
|
||||
switch (status) {
|
||||
case ServerStatus.unknown:
|
||||
return 'Loading...';
|
||||
case ServerStatus.ok:
|
||||
return 'Reachable';
|
||||
case ServerStatus.notOk:
|
||||
return 'Unexpected response';
|
||||
case ServerStatus.timeout:
|
||||
return 'Timeout';
|
||||
case ServerStatus.dnsError:
|
||||
return 'DNS issues';
|
||||
case ServerStatus.clientConnectivityIssues:
|
||||
return 'Connectivity issues on your device';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue