如何创建具有相同值但索引增加的100 map ?
我需要遵循这种结构
Map btnmap = {
"0": {
"a": Colors.grey[800],
"b": Colors.grey[800],
"c": Colors.grey[800],
"d": Colors.grey[800],
"s": false,
},
"1": {
"a": Colors.grey[800],
"b": Colors.grey[800],
"c": Colors.grey[800],
"d": Colors.grey[800],
"s": false,
},
"2": {
"a": Colors.grey[800],
"b": Colors.grey[800],
"c": Colors.grey[800],
"d": Colors.grey[800],
"s": false,
}, [...]
我正在尝试通过这种方式进行一些研究 Map<String,Color> btnMap = {
"a": Colors.grey[800],
"b": Colors.grey[800],
"c": Colors.grey[800],
"d": Colors.grey[800],
}
var list = List<Map>.filled(100, btnMap);
但这不能解决我的问题,因为我不能为每个索引增加++索引,我该如何解决?谢谢阅读。
最佳答案
您可以使用for
集合来实现您想要的东西:
final btnmap = {
for (var i = 0; i < 100; i++) '$i': {
"a": Colors.grey[800],
"b": Colors.grey[800],
"c": Colors.grey[800],
"d": Colors.grey[800],
"s": false,
},
};
Learn more about collection for。
关于flutter - 创建索引增加的抖动色图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63120487/