SpotifyApi class

Main class responsible for handling communication with Spotify Web API.

Inheritance
Available extensions

Constructors

SpotifyApi()
factory

Properties

accessToken String?
Currently active access token.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
playbackState PlaybackState?
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addToQueue(String uriToAdd, {String? deviceId}) Future<void>

Available on SpotifyApi, provided by the Player extension

Adds the item with the given uriToAdd to the end of the user's playback queue.
addTracksToPlaylist(String playlistId, List<String> trackUris, {int? position}) Future<void>

Available on SpotifyApi, provided by the PostMethods extension

Adds a list of track URIs to a playlist identified by playlistId. If position is provided, tracks are inserted at that position.
authenticate(String clientId, String redirectUri, [List<String>? scopes]) Future<void>
inherited
clearToken() Future<void>
Clears tokens from local storage and memory.
inherited
createPlaylist(String userId, String name, {String? description, bool? isPublic, bool? collaborative}) Future<Playlist>

Available on SpotifyApi, provided by the PostMethods extension

Creates a new playlist for a user with userId and name. Optional parameters: description, isPublic, collaborative. Returns the created Playlist.
currentUserFollows(List<String> ids, String type) Future<List<bool>>

Available on SpotifyApi, provided by the GetMethods extension

Checks if the current user follows given artists or users.
currentUserFollowsPlaylist(String playlistId) Future<bool>

Available on SpotifyApi, provided by the GetMethods extension

Checks if the current user follows a given playlist.
dispose() → void
Cancels any ongoing URI link stream.
inherited
followArtistsOrUsers(List<String> ids, String type) Future<void>

Available on SpotifyApi, provided by the PutMethods extension

Follows users or artists by ids. type must be either 'artist' or 'user'.
followArtistsOrUsers(List<String> ids, String type) Future<void>

Available on SpotifyApi, provided by the PostMethods extension

Follows a list of users or artists. type must be either 'artist' or 'user'.
followPlaylist(String playlistId, {bool? isPublic}) Future<void>

Available on SpotifyApi, provided by the PutMethods extension

Follows a playlist identified by playlistId. Optional isPublic sets whether the follow is public.
followPlaylist(String playlistId) Future<void>

Available on SpotifyApi, provided by the PostMethods extension

Follows a playlist specified by playlistId.
getAudioAnalysis(String trackId) Future<AudioAnalysis>

Available on SpotifyApi, provided by the GetMethods extension

Gets detailed audio analysis for a given track.
getAvailableDevices() Future<List<Device>>

Available on SpotifyApi, provided by the Player extension

Retrieves a list of available devices where playback can be controlled.
getAvailableGenreSeeds() Future<List<String>>

Available on SpotifyApi, provided by the GetMethods extension

Retrieves the list of available genre seeds for recommendations.
getAvailableMarkets() Future<List<String>>

Available on SpotifyApi, provided by the GetMethods extension

Retrieves the list of available Spotify markets.
getCurrentlyPlayingTrack() Future<Track?>

Available on SpotifyApi, provided by the Player extension

Gets the track currently playing on the user's active device. Returns null if nothing is playing or no device is active.
getCurrentUser() Future<User>

Available on SpotifyApi, provided by the GetMethods extension

Retrieves the current user's profile.
getFollowedArtists({int limit = 20, String? after}) Future<List<User>>

Available on SpotifyApi, provided by the GetMethods extension

Retrieves the list of artists followed by the current user.
getPlaybackState() Future<PlaybackState?>

Available on SpotifyApi, provided by the Player extension

Returns the current playback state of the user (device, progress, repeat mode, etc.) Returns null if nothing is currently playing or no active device.
getPlaylistTracks({required String playlistId, int offset = 0, int limit = 100}) Future<List<Track>>

Available on SpotifyApi, provided by the GetMethods extension

Retrieves tracks from a given playlist.
getQueue() Future<List<Track>>

Available on SpotifyApi, provided by the Player extension

Returns a list of tracks currently in the user's playback queue. The first track is the currently playing track (if present).
getRecentlyPlayed({int? limit, String? after, String? before}) Future<List<Track>>

Available on SpotifyApi, provided by the Player extension

Returns the user's recently played tracks. You can specify limit, after (timestamp in ms), or before to paginate.
getRecommendations({List<String>? seedTracks, List<String>? seedArtists, List<String>? seedGenres, Map<String, dynamic>? audioFeatures, String? market, int limit = 20}) Future<List<Track>>

Available on SpotifyApi, provided by the GetMethods extension

Gets track recommendations based on seeds and optional audio features.
getTrackById(String trackId) Future<Track>

Available on SpotifyApi, provided by the GetMethods extension

Retrieves details for a specific track by its ID.
getUserById(String userId) Future<User>

Available on SpotifyApi, provided by the GetMethods extension

Retrieves a user profile by user ID.
getUserPlaylists({int offset = 0, int limit = 50}) Future<List<Playlist>>

Available on SpotifyApi, provided by the GetMethods extension

Retrieves playlists of the current user.
getUserTopItems<T>({required String type, String timeRange = 'medium_term', int limit = 20, required T fromJson(Map<String, dynamic>)}) Future<List<T>>

Available on SpotifyApi, provided by the GetMethods extension

Gets the current user's top tracks or artists.
isTokenValid() Future<bool>
Checks if the stored access token is still valid.
inherited
isTrackInUserLikedTracks(String trackId) Future<bool>

Available on SpotifyApi, provided by the GetMethods extension

Returns true if the current user has liked a specific track. otherwise, returns false.
isUserAuthenticated() Future<bool>
Checks if the user is authenticated by verifying the access token.
logout() Future<void>
Clears the authentication data.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
refreshAccessToken() Future<void>
Refreshes the access token using the stored refresh token.
inherited
refreshPlaybackState() Future<void>

Available on SpotifyApi, provided by the Player extension

Refreshes the current playback state of the user.
removeSavedAlbums(List<String> albumIds) Future<void>

Available on SpotifyApi, provided by the DeleteMethods extension

Removes one or more albums from the user's Spotify library.
removeSavedTracks(List<String> trackIds) Future<void>

Available on SpotifyApi, provided by the DeleteMethods extension

Removes one or more tracks from the user's Spotify library.
saveAlbums(List<String> albumIds) Future<void>

Available on SpotifyApi, provided by the PostMethods extension

Saves a list of album IDs to the user's library.
saveAlbums(List<String> albumIds) Future<void>

Available on SpotifyApi, provided by the PutMethods extension

Saves a list of album IDs to the user's library.
saveTracks(List<String> trackIds) Future<void>

Available on SpotifyApi, provided by the PostMethods extension

Saves a list of track IDs to the user's library.
saveTracks(List<String> trackIds) Future<void>

Available on SpotifyApi, provided by the PutMethods extension

Saves a list of track IDs to the user's library.

Available on SpotifyApi, provided by the GetMethods extension

Performs a search across Spotify content.
seekToPosition(Duration position, {String? deviceId}) Future<void>

Available on SpotifyApi, provided by the Player extension

Seeks to the given position in the currently playing track.
setRepeatMode(String state, {String? deviceId}) Future<void>

Available on SpotifyApi, provided by the Player extension

Sets the repeat mode for playback. Valid state values are 'track', 'context', or 'off'.
setShuffle(bool shuffle, {String? deviceId}) Future<void>

Available on SpotifyApi, provided by the Player extension

Enables or disables shuffle mode for playback.
setVolume(int volumePercent, {String? deviceId}) Future<void>

Available on SpotifyApi, provided by the Player extension

Sets the playback volume to volumePercent, which must be between 0 and 100.
skipToNext({String? deviceId}) Future<void>

Available on SpotifyApi, provided by the Player extension

Skips to the next track in the user's queue.
skipToPrevious({String? deviceId}) Future<void>

Available on SpotifyApi, provided by the Player extension

Skips to the previous track in the user's queue.
startOrResumePlayback({String? deviceId}) Future<void>

Available on SpotifyApi, provided by the Player extension

Starts or resumes playback on the user's active device. Optionally targets a specific deviceId.
togglePlayback() Future<void>

Available on SpotifyApi, provided by the Player extension

Toggles playback: pauses if playing, resumes if paused. Does nothing if there's no active device or no track is currently playing.
toString() String
A string representation of this object.
inherited
transferPlayback(String deviceId, {bool play = true}) Future<void>

Available on SpotifyApi, provided by the Player extension

Transfers playback to a specific device. If play is true, playback will start on the new device.
tryRestoreToken() Future<bool>
Attempts to restore saved tokens from local storage.
inherited
unfollowArtists(List<String> artistIds) Future<void>

Available on SpotifyApi, provided by the DeleteMethods extension

Unfollows one or more artists for the current user.
unfollowPlaylist(String playlistId) Future<void>

Available on SpotifyApi, provided by the DeleteMethods extension

Unfollows a playlist for the current user.
updatePlaylistDetails(String playlistId, {String? name, String? description, bool? isPublic, bool? collaborative}) Future<void>

Available on SpotifyApi, provided by the PutMethods extension

Updates details of an existing playlist identified by playlistId. Optional parameters can update the name, description, visibility, and collaboration status.

Operators

operator ==(Object other) bool
The equality operator.
inherited