flutter - 创建索引增加的抖动色图

标签 flutter dart

如何创建具有相同值但索引增加的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/

相关文章:

exception - 在 Dart 中管理登录/功能错误的最佳做法是什么?

android - 使用来自letsencrypt的证书与 flutter

flutter - 绘制一个带边框的椭圆来显示图像

firebase - 检测到零个或 2 个或更多 [DropdownMenuItem] 具有相同的值

flutter - 在 flutter 构建之前运行自定义命令?

android - Android 13 的 flutter 相机 : my app keeps crashing

Flutter ListWheelScrollView

flutter - 什么时候在 flutter 应用程序中使用 "new"构造函数?

dart - 带有文本标签的 float 操作按钮。 flutter

dart - HttpClientRequest 添加数据失败