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();
![Flutter開発で知らないと損すること](https://417.run/wp-content/uploads/2021/12/image-1639790999665.png)