我有表单字段“服务器名称”、“服务器IP”、“数据库”和“端口”。我需要的服务器名称字段是一个下拉列表,其值是从下面的List<Map<String, Map<String, String>>>
键serverName1
和serverName2
。然后,当用户选择其中一个时,其他字段应使用适当的嵌套值(服务器IP、数据库、端口)进行更新。我该怎么做?
class GlobalsProvider {
List<Map<String, Map<String, String>>> getServers() {
final serverList = [{
'serverName1': {
'Server IP': 'ip1',
'Database': 'db1',
'Port': 'port1'
},
'serverName2': {
'Server IP': 'ip2',
'Database': 'db2',
'Port': 'port2'
}
}];
return serverList;
}
}
@override
Widget build(BuildContext context) {
return Consumer<GlobalsProvider>(
builder: (context, value, child) => Scaffold(
appBar: AppBar(
title: const Text('Login'),
centerTitle: true,
actions: [
IconButton(
onPressed: () {},
icon: const Icon(Icons.add)
),
],
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: 2,
child: Visibility(
visible: true,
child: Row(
children: [
const Expanded(child: Text('Server Name:')),
DropdownButton(
//? Not sure how to do this part
)
],
),
),
),
Expanded(
flex: 2,
child: Visibility(
visible: true,
child: Row(
children: [
const Expanded(child: Text('Server IP:')),
Expanded(
child: TextField(
controller: serverIPController,
),
),
],
),
),
),
Expanded(
flex: 2,
child: Visibility(
visible: true,
child: Row(
children: [
const Expanded(child: Text('Database:')),
Expanded(
child: TextField(
controller: dbController,
),
),
],
),
),
),
Expanded(
flex: 2,
child: Visibility(
visible: true,
child: Row(
children: [
const Expanded(child: Text('Port:')),
Expanded(
child: TextField(
controller: portController,
),
),
],
),
),
),
//...
1条答案
按热度按时间bvjveswy1#
您有一个列表项和两个服务器。在这种情况下,它将是