English 中文(简体)
显示名单<Map<String, Map<String, String>。 A. 降低并更新具有根基的其他领域
原标题:Display a List<Map<String, Map<String, String>>> in a dropdown and update other fields with nested values

我有田地服务器名称、服务器IP、数据库和港口。 我需要服务器名称领域为下级,其价值为serverName1serverName2,分别来自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,
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                 //...
问题回答

您有一个单一清单项目,有两个服务器。 在这种情况下,

  String? selectedServer;

  final TextEditingController serverIPController = TextEditingController();
  void onServerChanged(String? value) {
    setState(() {
      selectedServer = value; 
                                /// having single item on the list, so index is 0
      serverIPController.text = serverList[0][selectedServer]?[ Server IP ] ?? "";
    });
  }
Row(
  children: [
    Text( Server ),
    Expanded(
      child: DropdownButton<String>(
        value: selectedServer,
        hint: const Text( Select Server ),
        items: serverList[0].keys.map((String value) {
          return DropdownMenuItem<String>(
            value: value,
            child: Text(value),
          );
        }).toList(),
        onChanged: onServerChanged,
      ),
    ),
  ],
),
Row(
  children: [
    const Expanded(child: Text( Server IP: )),
    Expanded(child: TextField(controller: serverIPController)),
  ],
),




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签