Hey!
Today I’d like to my experience working with Dart Spotify SDK.
If you didn’t know, Spotify API is free to use! (But apparently not totally since you need a Premium account). So you can build your own apps using it.
Spotify API was really hard for to use so I searched for an SDK that would make my life easier. And I found it in Dart Spotify SDK. I used it to create a simple application on Flutter that just displays some information about albums and songs that they consist. It was an assignment in my university so I didn’t really have much time to explore Spotify API from start to finish, but I hope my little work may help someone.
Here’s the steps in getting started with Dart Spotify SDK:
- We need to add the dependencies:
dependencies: flutter: sdk: flutter # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.6 spotify: ^0.13.5
Perfect!
Now onto the next step, which is just importing the dependency:
import "package:spotify/spotify.dart";
We can start using it now! But at first, you will have to create your application in Spotify Developer Dashboard where you’ll aquire your client_id and client_secret. You need them to authorize your app:
- To do that, go to Spotify For Developers -> Dashboard; and create application.
- Client id and client secret will be available in the application settings
- Now let’s get back to coding:
late SpotifyApiCredentials credentials;
late SpotifyApi spotify; @override void initState() { super.initState(); credentials = SpotifyApiCredentials(clientId, clientSecret); spotify = SpotifyApi(credentials); }
Store them in variables (but note that those keys should be hidden from public view so it’s better to store them in env files)
- Great! We have initialized our application and now can start making api calls!
spotify.albums.get("4PWBTB6NYSKQwfo79I3prg")
This call will get information about some particular album, with the list of songs, albums length, artist, album cover and more! (I suspect that it is even possible to play the songs, but not sure)
And just like that, you can experement with it and maybe recreate Spotify for your portforlio!
P.S. I am not an expert either in flutter or spotify api, I’d be happy to get some tips regarding my code, or to receive some feedback from more experienced developers!
Discover more from Coursity
Subscribe to get the latest posts sent to your email.