Getting type 'Null' is not a subtype of type 'Map<String, dynamic>' on the example code
Closed this issue · 3 comments
Victorhin00 commented
Hello, i have a little problem.
I've copied the example script from here : https://pub.dev/packages/spotify/example , just i've kept only the search section. None of the code is changed. Everything is original.
My code is :
var credentials = SpotifyApiCredentials('id','secret');
var spotify = SpotifyApi(credentials);
print("\nSearching for \'Metallica\':");
var search = await spotify.search
.get('metallica')
.first(2)
.catchError((err) => print((err as SpotifyException).message));
if (search == null) {
return;
}
search.forEach((pages) {
pages.items!.forEach((item) {
if (item is PlaylistSimple) {
print('Playlist: \n'
'id: ${item.id}\n'
'name: ${item.name}:\n'
'collaborative: ${item.collaborative}\n'
'href: ${item.href}\n'
'trackslink: ${item.tracksLink!.href}\n'
'owner: ${item.owner}\n'
'public: ${item.owner}\n'
'snapshotId: ${item.snapshotId}\n'
'type: ${item.type}\n'
'uri: ${item.uri}\n'
'images: ${item.images!.length}\n'
'-------------------------------');
}
if (item is Artist) {
print('Artist: \n'
'id: ${item.id}\n'
'name: ${item.name}\n'
'href: ${item.href}\n'
'type: ${item.type}\n'
'uri: ${item.uri}\n'
'-------------------------------');
}
if (item is TrackSimple) {
print('Track:\n'
'id: ${item.id}\n'
'name: ${item.name}\n'
'href: ${item.href}\n'
'type: ${item.type}\n'
'uri: ${item.uri}\n'
'isPlayable: ${item.isPlayable}\n'
'artists: ${item.artists!.length}\n'
'availableMarkets: ${item.availableMarkets!.length}\n'
'discNumber: ${item.discNumber}\n'
'trackNumber: ${item.trackNumber}\n'
'explicit: ${item.explicit}\n'
'-------------------------------');
}
if (item is AlbumSimple) {
print('Album:\n'
'id: ${item.id}\n'
'name: ${item.name}\n'
'href: ${item.href}\n'
'type: ${item.type}\n'
'uri: ${item.uri}\n'
'albumType: ${item.albumType}\n'
'artists: ${item.artists!.length}\n'
'availableMarkets: ${item.availableMarkets!.length}\n'
'images: ${item.images!.length}\n'
'releaseDate: ${item.releaseDate}\n'
'releaseDatePrecision: ${item.releaseDatePrecision}\n'
'-------------------------------');
}
});
});
var relatedArtists =
await spotify.artists.relatedArtists('0OdUWJ0sBjDrqHygGUXeCF');
print('\nRelated Artists: ${relatedArtists.length}');
credentials = await spotify.getCredentials();
print('\nCredentials:');
print('Client Id: ${credentials.clientId}');
print('Access Token: ${credentials.accessToken}');
print('Credentials Expired: ${credentials.isExpired}');
}
I keep getting the songs, which is a good thing, but i have this error as well. I'm still a beginner on dart, so i dont really know how to solve this one.
-------------------------------
Track:
id: 0LAcM6I7ijW4VVW0aytl1t
name: One (Remastered)
href: https://api.spotify.com/v1/tracks/0LAcM6I7ijW4VVW0aytl1t
type: track
uri: spotify:track:0LAcM6I7ijW4VVW0aytl1t
isPlayable: null
artists: 1
availableMarkets: 2
discNumber: 1
trackNumber: 4
explicit: false
-------------------------------
Unhandled exception:
type 'Null' is not a subtype of type 'Map<String, dynamic>'
#0 Search.get.<anonymous closure> (package:spotify/src/endpoints/search.dart:40:40)
#1 MappedListIterable.elementAt (dart:_internal/iterable.dart:413:31)
#2 ListIterable.forEach (dart:_internal/iterable.dart:39:14)
#3 main.<anonymous closure> (package:playit/scripts/spotify.dart:25:18)
#4 List.forEach (dart:core-patch/growable_array.dart:433:8)
#5 main (package:playit/scripts/spotify.dart:24:10)
<asynchronous suspension>
Thanks for reading me
Victorhin00 commented
After investigation, it seems that the 4th value of the list returned by the api is bugged. Simply remove it with this
for (var pages in search) {
a.add(pages);
}
a.remove(a[4]);
letyletylety commented
is this problem from spotify api or from this plugin?
rinukkusu commented
Probably a mapping error somewhere - needs investigation!