如何在 Flutter 中将地图列表显示到 DropdownMenuItem 中

lat*_*der 8 list dart flutter

我是 Flutter 新手。\n我想从列表变量中显示 DropdownMenuItem。\n查看我的代码。

\n\n
\n// my list variable\n\n\n  List listUserType = [\n    {'name': 'Individual', 'value': 'individual'},\n    {'name': 'Company', 'value': 'company'}\n  ];\n\n\n\n\n// items property in DropdownMenuItem\n\nreturn DropdownButtonFormField<List<Map>>(\n        decoration: InputDecoration(\n          prefixIcon: Icon(Icons.settings),\n          hintText: 'Organisation Type',\n          filled: true,\n          fillColor: Colors.white,\n          errorStyle: TextStyle(color: Colors.yellow),\n        ),\n        items: listUserType.map((map) {\n          return DropdownMenuItem(\n            child: Text(map['name']),\n            value: map['value'],\n          );\n        }).toList());\n
Run Code Online (Sandbox Code Playgroud)\n\n

这是我得到的结果

\n\n
I/flutter (22528): \xe2\x95\x90\xe2\x95\x90\xe2\x95\xa1 EXCEPTION CAUGHT BY WIDGETS LIBRARY \xe2\x95\x9e\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nI/flutter (22528): The following assertion was thrown building RegisterPage(dirty, state: RegisterPageState#5b83a):\nI/flutter (22528): type 'List<DropdownMenuItem<dynamic>>' is not a subtype of type\nI/flutter (22528): 'List<DropdownMenuItem<List<Map<dynamic, dynamic>>>>'\n
Run Code Online (Sandbox Code Playgroud)\n\n

我不知道是什么导致了错误。

\n

Jac*_*ins 9

尝试删除<List<Map>>

return DropdownButtonFormField(
        decoration: InputDecoration(
          prefixIcon: Icon(Icons.settings),
          hintText: 'Organisation Type',
          filled: true,
          fillColor: Colors.white,
          errorStyle: TextStyle(color: Colors.yellow),
        ),
        items: listUserType.map((map) {
          return DropdownMenuItem(
            child: Text(map['name']),
            value: map['value'],
          );
        }).toList());
Run Code Online (Sandbox Code Playgroud)