如果我说 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
)
Run Code Online (Sandbox Code Playgroud)
我通过List<Widget>在 return 语句上方预先创建一个来解决它,但只是为了方便(并在 Dart 中变得更好)我想知道是否有办法内联。
Tru*_*inh 29
更新答案以包含 @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());
;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14967 次 |
| 最近记录: |