searchForPlaylist method
Search for playlists on Spotify.
Note
- Same as results on the playlist tab, but excluding the user's own playlists. Best for Spotify-owned playlists.
Implementation
Future<List<Playlist>> searchForPlaylist(
String query, [
int itemCount = 5,
]) async {
var resultPages =
await _spotifyEngine.search.get(query, types: [SearchType.playlist]).first(itemCount);
var results = <Playlist>[];
for (var page in resultPages) {
if (page.items != null) {
// `page.items` is apparently a `MappedListIterable`, whatever that is,
// so I'd rathe typecast the `item` instead.
for (var item in page.items!) {
var playlist = item as PlaylistSimple;
results.add(
Playlist(
name: playlist.name!,
user: playlist.owner!.displayName!,
url: 'https://open.spotify.com/playlist/${playlist.id!}',
),
);
}
}
}
return results;
}