Creating a list of widgets from map with keys and values

前端 未结 1 1492
有刺的猬
有刺的猬 2021-02-13 13:54

If I have say a SimpleDialog() and it accepts children[] and I want to populate it from a Map, how would I do that? I n

相关标签:
1条回答
  • 2021-02-13 14:33

    Update answer to incorporate @lrn 's comment

    You can use map

    const optionsMap = {
        111:"First option",
        222:"Second option",
    }     
        return SimpleDialog(
            title: Text('Choose one'),
            children: optionsMap.entries.map((entry) {
              var w = Text(entry.value);
              doSomething(entry.key);
              return w;
            }).toList());
    ;
    
    0 讨论(0)
提交回复
热议问题