dartで配列から、DropdownMenuItem
を作るために、
map関数
でindex
を取得したかったので調べました。
map関数でindexを取得する方法
ListをasMapでMap型に変換して、それをentries
という形にすると
entry
の配列みたいなのになるので、そこからkeyとvalueが取得できる
例
['test', 'test2'].asMap().entries.map((entry) => DropdownMenuItem(
value: entry.key.toString(),
child: Text(entry.value),
)).toList();
