'WhereIterable<Map<dynamic, dynamic>>' is not a subtype of type 'List<Map<dynamic, dynamic>>'

Viewed 490

Someone please help... I am going mad with this!

if I have:

void main() {
  List<Map> people = [];

  people.add({'name': 'Patrick', 'age': 56});
  people.add({'name': 'Jeannette', 'age': 55});

  print(people.where((person) => person['name'] == 'Patrick'));
}

as expected the output is: ({name: Patrick, age: 56})

but if I put the where in a class, like this:

class People {
  List<Map> people = [];

  void add(Map data) {
    people.add(data);
  }

  List<Map> get filtered {
    return people.where((m) => m['name'] == 'Patrick');
  }
}

void main() {
  People people = People();

  people.add({'name': 'Patrick', 'age': 56});
  people.add({'name': 'Jeannette', 'age': 55});

  print(people.filtered);
}

I get: Unhandled exception: type 'WhereIterable<Map<dynamic, dynamic>>' is not a subtype of type 'List<Map<dynamic, dynamic>>' #0 People.filtered (file:///C:/flutter/apps/mapDB/scratch.dart:9:5) #1 main (file:///C:/flutter/apps/mapDB/scratch.dart:19:16) #2 _delayEntrypointInvocation. (dart:isolate-patch/isolate_patch.dart:283:19) #3 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

0 Answers
Related