Ian M
Ian M

Reputation: 355

Flutter confusing nested list with object

This would work fine in JS, but Dart (Flutter) is having a heart attack. Any idea why ??

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]);
}

Upvotes: 0

Views: 239

Answers (1)

KuKu
KuKu

Reputation: 7492

Please try like below

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]);
}

Upvotes: 1

Related Questions