如果我说了aSimpleDialog()
并且它接受children[]
并且我想从a填充它Map<int, String>
,我该怎么做?我需要键和值来创建子窗口小部件。
const optionsMap = {
111:"First option",
222:"Second option",
}
return SimpleDialog(
title: Text('Choose one'),
children: // I don't know what to put here
// I want to have widgets based on optionsMap keys and values
)
我通过List<Widget>
在return语句上方预先创建一个问题来解决它,但是为了方便起见(在Dart中变得更好),我想知道是否有一种内联的方法。
更新答案以包含@lrn的评论
您可以使用 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());
;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句