Added the ability to edit Servers #18

Closed
Hugo Bayer wants to merge 1 commits from Hugo/104729012020/AddedTheAbilityToEditServers into master
1 changed files with 65 additions and 2 deletions

View File

@ -212,6 +212,70 @@ class _ServerListState extends State<ServerList> {
});
}
void _modifyServerForm(Server server){
TextEditingController servername = TextEditingController(text: server.displayName);
TextEditingController uri = TextEditingController(text: server.uri);
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(
decoration: InputDecoration(
labelText: 'Custom Name',
),
controller: servername,
),
TextFormField(
controller: uri,
decoration: InputDecoration(
labelText: 'URI',
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(children: [
Expanded(
child: RaisedButton(
child: Text("Confirm"),
onPressed: () {
if (_formKey.currentState.validate()) {
_formKey.currentState.save();
Navigator.of(context).pop();
}
},
),
),
RaisedButton(
child: Text("Confirm"),
onPressed: () {
if (_formKey.currentState.validate()) {
_formKey.currentState.save();
setState(() {
server.displayName=servername.text;
server.uri = uri.text;
});
Navigator.of(context).pop();
}
},
)
]),
)
],
),
),
),
);
},
);
}
List<Widget> _createChildren() {
List<Widget> list = new List<Widget>.generate(servers.length, (int index) {
Widget info = Row(children: [
@ -313,7 +377,7 @@ class _ServerListState extends State<ServerList> {
color: Colors.grey,
),
onPressed: () {
_removeServer(index);
_modifyServerForm(servers[index]);
},
),
]),
@ -326,7 +390,6 @@ class _ServerListState extends State<ServerList> {
setState(() {
selectedServer = index;
});
print(index.toString() + " clicked");
},
child: Container(
width: MediaQuery.of(context).size.width,