I am currently learning Flutter and Dart to try to expand my knowledge. The problem I'm having is due to changing from Dart 1.0 to Dart 2.0, leading me to think that the problem resides in the change of type mode. My code:
I'm playing with a Spotify library that does this:
object.artists = (map['artists'] as List<dynamic>)
?.map(ArtistSimpleMapper.parse)
?.toList();
The parse method from the class ArtistsSimpleMapper is the following:
/// Converts a Map to an instance of Image.
static Image parse(Map<String, dynamic> map) {
if (map == null) return null;
final Image object = new Image();
object.height = map['height'];
object.width = map['width'];
object.url = map['url'];
return object;
}
My most successful approach has been using .cast<dynamic>()
, the code failed at runtime instead of compile time, needless to say I'm completely lost on how to follow or how to solve this problem.
Error:
Error: A value of type '(dart.core::Map<dart.core::String, dynamic>) → spotify::ArtistSimple' can't be assigned to a variable of type '(dynamic) → dart.core::Object'.
?.map(ArtistSimpleMapper.parse)
^
Post read: link