arrays - 我怎样才能在 Dart 中做一组地图对象
问题描述
我是 Dart 和 Flutter 的新手,我想不通,我想创建一个数组,其中每个元素都是一个地图对象,这样我就可以用类似的东西来引用它: thisVar = myArray[0]['我的元素']。这样我就可以从不同的数组索引动态访问不同的项目。
//this is in my data file
var tox = [
{"icon": Icons.help, "color": Colors.black38, "text": "Inconnue"},
{"icon": Icons.check_circle, "color": Colors.green, "text": "C'est bon"},
{"icon": Icons.error, "color": Colors.yellow[500], "text": "À l'occasion"},
{"icon": Icons.cancel, "color": Colors.amber[500], "text": "Douteux"},
{"icon": Icons.cancel, "color": Colors.orange[800], "text": "Toxique"},
{"icon": Icons.cancel, "color": Colors.red[900], "text": "Très toxicité"},
];
// this is in my home page
Column(children: <Widget>[
Icon(tox[0]['icon'],
color: tox[0]['color']),
Text(tox[0]['text']),
],
)
我得到错误:类'int'没有实例方法'[]'