type '(dynamic) => dynamic' is not a subtype of type '(dynamic) => bool' of 'test' when I use map function type '(dynamic) => dynamic' is not a subtype of type '(dynamic) => bool' of 'test' when I use map function dart dart

type '(dynamic) => dynamic' is not a subtype of type '(dynamic) => bool' of 'test' when I use map function


I solved with this code:

function filter(_items) {    return _items.map((day, items) {        return new MapEntry(day, items.where((i) {          return i.stringProperty.contains(widget.filter) ? true : false;        }).toList());    });}

It seems the contains function does not return a bool value.


I believe this will also work, still not sure why it doesn't return a bool though

function filter(_items) {    return _items.map((day, items) {        return new MapEntry(day, items.where((i) {          return (i.stringProperty.contains(widget.filter)) as bool;        }).toList());    });}


Where method returns a list, so you don't need to use toList(), and you should specify the return type of map method when you are using it.

  filter(_items) {    return _items.map<String, List<bool>>((day, items) {      return MapEntry(        day, items.where((i) => i.stringProperty.contains(widget.filter)),      );    });  }