我有田地服务器名称、服务器IP、数据库和港口。 我需要服务器名称领域为下级,其价值为serverName1
和serverName2
,分别来自List<Map<String, Map<String, String>>>
。 然后,如果用户选择其中一种,则其他领域应当更新适当的附加价值(Server IP, Database, Port)。 我如何这样做?
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,
),
),
],
),
),
),
//...