feat: no pop when deleting the config
This commit is contained in:
@@ -302,130 +302,139 @@ class _ControlPageState extends State<ControlPage> {
|
|||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
SavedConnection? selectedSavedConnection;
|
|
||||||
showDialog<String>(
|
showDialog<String>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) => Dialog(
|
builder: (BuildContext context) => StatefulBuilder(
|
||||||
child: Padding(
|
builder:
|
||||||
padding: const EdgeInsets.all(8.0),
|
(BuildContext context, StateSetter setState) {
|
||||||
child: Column(
|
SavedConnection? selectedSavedConnection;
|
||||||
mainAxisSize: MainAxisSize.min,
|
return Dialog(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
child: Padding(
|
||||||
children: <Widget>[
|
padding: const EdgeInsets.all(8.0),
|
||||||
Builder(builder: (context) {
|
child: Column(
|
||||||
String jsonString =
|
mainAxisSize: MainAxisSize.min,
|
||||||
SharedPrefSingleton().savedConnection;
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
List<dynamic> nodeList = jsonDecode(jsonString);
|
children: <Widget>[
|
||||||
List<SavedConnection> nodes = nodeList
|
Builder(builder: (context) {
|
||||||
.cast<Map<String, dynamic>>()
|
String jsonString =
|
||||||
.map((nodeData) =>
|
SharedPrefSingleton().savedConnection;
|
||||||
SavedConnection.fromJson(nodeData))
|
List<dynamic> nodeList =
|
||||||
.toList();
|
jsonDecode(jsonString);
|
||||||
|
List<SavedConnection> nodes = nodeList
|
||||||
|
.cast<Map<String, dynamic>>()
|
||||||
|
.map((nodeData) =>
|
||||||
|
SavedConnection.fromJson(nodeData))
|
||||||
|
.toList();
|
||||||
|
|
||||||
return StatefulBuilder(builder:
|
return StatefulBuilder(builder:
|
||||||
(BuildContext context,
|
(BuildContext context,
|
||||||
StateSetter setState) {
|
StateSetter setState) {
|
||||||
return DropdownButton(
|
return DropdownButton(
|
||||||
value: selectedSavedConnection,
|
value: selectedSavedConnection,
|
||||||
items: nodes.map<
|
items: nodes.map<
|
||||||
DropdownMenuItem<
|
DropdownMenuItem<
|
||||||
SavedConnection>>(
|
SavedConnection>>(
|
||||||
(SavedConnection value) {
|
(SavedConnection value) {
|
||||||
return DropdownMenuItem<
|
return DropdownMenuItem<
|
||||||
SavedConnection>(
|
SavedConnection>(
|
||||||
value: value,
|
value: value,
|
||||||
child: Text(value.name),
|
child: Text(value.name),
|
||||||
);
|
);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState(
|
setState(
|
||||||
() {
|
() {
|
||||||
selectedSavedConnection = value!;
|
selectedSavedConnection = value!;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
const SizedBox(height: 15),
|
||||||
|
Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
if (selectedSavedConnection != null) {
|
||||||
|
_supernodeController.text =
|
||||||
|
selectedSavedConnection!
|
||||||
|
.supernode;
|
||||||
|
_communityController.text =
|
||||||
|
selectedSavedConnection!
|
||||||
|
.community;
|
||||||
|
_keyController.text =
|
||||||
|
selectedSavedConnection!
|
||||||
|
.communityKey;
|
||||||
|
_selfAddressController.text =
|
||||||
|
selectedSavedConnection!
|
||||||
|
.selfAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
Navigator.pop(context);
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
child: Text(
|
||||||
|
AppLocalizations.of(context)!.use),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
if (selectedSavedConnection == null) {
|
||||||
|
Navigator.pop(context);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String jsonString =
|
||||||
|
SharedPrefSingleton()
|
||||||
|
.savedConnection;
|
||||||
|
List<dynamic> nodeList =
|
||||||
|
jsonDecode(jsonString);
|
||||||
|
List<SavedConnection> nodes = nodeList
|
||||||
|
.cast<Map<String, dynamic>>()
|
||||||
|
.map((nodeData) =>
|
||||||
|
SavedConnection.fromJson(
|
||||||
|
nodeData))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
nodes.removeWhere(
|
||||||
|
(element) {
|
||||||
|
return element.name ==
|
||||||
|
selectedSavedConnection!.name;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
const SizedBox(height: 15),
|
|
||||||
Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
if (selectedSavedConnection != null) {
|
|
||||||
_supernodeController.text =
|
|
||||||
selectedSavedConnection!.supernode;
|
|
||||||
_communityController.text =
|
|
||||||
selectedSavedConnection!.community;
|
|
||||||
_keyController.text =
|
|
||||||
selectedSavedConnection!
|
|
||||||
.communityKey;
|
|
||||||
_selfAddressController.text =
|
|
||||||
selectedSavedConnection!
|
|
||||||
.selfAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
Navigator.pop(context);
|
List<Map<String, dynamic>> nodeMaps =
|
||||||
return;
|
nodes
|
||||||
},
|
.map((node) => node.toJson())
|
||||||
child:
|
.toList();
|
||||||
Text(AppLocalizations.of(context)!.use),
|
SharedPrefSingleton()
|
||||||
),
|
.setSavedConnection(
|
||||||
TextButton(
|
jsonEncode(nodeMaps))
|
||||||
onPressed: () {
|
.then((onValue) {
|
||||||
if (selectedSavedConnection == null) {
|
setState(() {});
|
||||||
|
// Navigator.pop(context);
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: Text(
|
||||||
|
AppLocalizations.of(context)!.delete),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
return;
|
return;
|
||||||
}
|
},
|
||||||
|
child: Text(
|
||||||
String jsonString =
|
AppLocalizations.of(context)!.cancel),
|
||||||
SharedPrefSingleton().savedConnection;
|
),
|
||||||
List<dynamic> nodeList =
|
],
|
||||||
jsonDecode(jsonString);
|
),
|
||||||
List<SavedConnection> nodes = nodeList
|
],
|
||||||
.cast<Map<String, dynamic>>()
|
),
|
||||||
.map((nodeData) =>
|
|
||||||
SavedConnection.fromJson(
|
|
||||||
nodeData))
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
nodes.removeWhere(
|
|
||||||
(element) {
|
|
||||||
return element.name ==
|
|
||||||
selectedSavedConnection!.name;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
List<Map<String, dynamic>> nodeMaps =
|
|
||||||
nodes
|
|
||||||
.map((node) => node.toJson())
|
|
||||||
.toList();
|
|
||||||
SharedPrefSingleton()
|
|
||||||
.setSavedConnection(
|
|
||||||
jsonEncode(nodeMaps))
|
|
||||||
.then((onValue) {
|
|
||||||
Navigator.pop(context);
|
|
||||||
return;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
child: Text(
|
|
||||||
AppLocalizations.of(context)!.delete),
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pop(context);
|
|
||||||
return;
|
|
||||||
},
|
|
||||||
child: Text(
|
|
||||||
AppLocalizations.of(context)!.cancel),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
),
|
}),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: Text(AppLocalizations.of(context)!.useConfig)),
|
child: Text(AppLocalizations.of(context)!.useConfig)),
|
||||||
|
Reference in New Issue
Block a user