【问题标题】:How to use a Map<int, String> with the DropDownMenu Widget Flutter如何将 Map<int, String> 与 DropDownMenu Widget Flutter 一起使用
【发布时间】:2021-07-10 23:27:39
【问题描述】:

我一直在尝试实现一个下拉菜单,但我想利用地图的关键数据。

我要处理的数据的一个简单示例

List<String> Test = [ Test1,Test2,Test3,Test4 ];
Map<int,String> Test2 = { 0 : Test1 , 1 : Test2, 2: Test3, 3:Test4};

我的列表版本:

  EM.DigitalFunctionList.map((String item) => DropdownMenuItem<String>(
     value: item,
      child: Text("$item and ${item.indexOf($item)}"),
  ),).toList(),
    ),

目前这会为所有值返回一个“项目 x 和 0”,所以我不太确定为什么会这样,但是

Link

它声明要从列表中获取索引,您必须将其转换为地图,所以我有点难过

【问题讨论】:

  • pattern 的值是多少?
  • 对不起,这应该是项目字符串,所以它会查找它。我确实找到了一种通过使用我的地图获取索引的方法,但如果可能的话,我宁愿完全使用地图

标签: list flutter dictionary dart dropdown


【解决方案1】:

将其更改为您正在尝试获取父列表中项目的索引 EM.DigitalFunctionList.indexOf($item)

【讨论】:

  • 嗯,好的。为回复干杯!!我明天给它一个wiz并更新帖子!
猜你喜欢
  • 2018-04-06
  • 1970-01-01
  • 2010-12-23
  • 1970-01-01
  • 2021-12-20
  • 1970-01-01
  • 2023-03-26
  • 1970-01-01
  • 2023-03-15
相关资源
最近更新 更多