Home > front end >  why dart Map returns null?
why dart Map returns null?

Time:10-14

I'm trying to sum Map values. but i am getting error. I think it's because Map returns null. I will be glad if you help.

I try that code;

void main() {
  List t = ['tag1', 'tag2'];
  List f = ['1', '2', '3'];
  List data = [
    ['1', 0.5, 0.6],
    ['2', 0.7, 0.8],
    ['3', 0.9, 1]
  ];
  Map answers = {};
  for (final i in data) {
    answers[i[0]] = i.skip(1);
  }

  var qSum = 0.0;
  for (int tg = 0; tg < t.length; tg  ) {
    for (final i in f) {
      var val = answers[i][tg];
      qSum = qSum   (val);
    }
  }
}

CodePudding user response:

It's because skip returns an Iterable and not a List. Change

answers[i[0]] = i.skip(1);

to

answers[i[0]] = i.skip(1).toList();
  • Related