searchForAlbum method
Search for albums on Spotify.
Implementation
Future<List<Album>> searchForAlbum(String query, [int itemCount = 5]) async {
var resultPages =
await _spotifyEngine.search.get(query, types: [SearchType.album]).first(itemCount);
var results = <Album>[];
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 album = item as AlbumSimple;
results.add(
Album(
name: album.name!,
artist: album.artists!.first.name!,
albumUrl: 'https://open.spotify.com/album/${album.id!}',
artUrl: album.images!.first.url!,
),
);
}
}
}
return results;
}