扑朔迷离的嵌套列表与对象

时间:2020-03-08 07:52:50

标签: flutter dart

这在JS中可以正常工作,但是Dart(Flutter)心脏病发作。知道为什么吗??

void main() {
  var foo = [
    {
      "some": "thing",  // comment this line and it works ??
      "test": ["one", "two", "three"]
    }
  ];

  // The operator '[]' isn't defined for the class 'Object'
  print(foo[0]["test"][0]);
}

1 个答案:

答案 0 :(得分:1)

请尝试如下

void main() {
  List foo = [
    {
      "some": "thing",  // comment this line and it works ??
      "test": ["one", "two", "three"]
    }
  ];

  // The operator '[]' isn't defined for the class 'Object'
  print(foo[0]["test"][0]);
}