spotify_flutter 0.0.2 copy "spotify_flutter: ^0.0.2" to clipboard
spotify_flutter: ^0.0.2 copied to clipboard

An api for interacting with Spotify Web Api

This is a library that helps with interfacing with the Spotify Api.

Features #

This package can help you interact with the following sections under the Spotify Api

  • Artists
  • Users
  • Albums
  • Genre
  • Playlist

Getting started #

Get your api keys from Spotify.

The project requires a minimum SDK version on Android of 18.

Add this to your Manifest File on Android.

        <intent-filter android:label="flutter_web_auth">

            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data android:scheme="[INSERT_YOUR_CALLBACK_SCHEME]" />


        </intent-filter>
    </activity>

Usage #

Authentication: #

Ensure to authenticate first before using any of the methods. Do not forget to add your REDIRECT URI in your spotify dashboard and ensure they are the same as the one used to authenticate.

Hint: Your redirect Uri should be [YOUR_CALL_BACK_SCHEME]://[ANYTHING_YOU_WANT].com

Future authenticate() async {
  final authClient = spotifyApiGateway.authClient;
  final keyPair = authClient.getKeyPair();
  try {
    String redirectUri = 'spotify://spotify.flutter.com';

    final code = await authClient.authorize(
      redirectUri: '[INSERT_YOUR_REDIRECT_URI]',
      clientId: '[INSERT_YOUR_CLIENT_ID]',
      callbackUrlScheme: '[INSERT_YOUR_CALL_BACK_SCHEME]',
      scope: '[INSERT_YOUR_SCOPE_HERE]',
      codeChallenge: keyPair.codeChallenge,
    );

    if (code == null) {
      //Handle failure
      return;
    }

    //retrieve auth and refresh tokens.
    final tokenResponse = await authClient.getToken(
      code: code,
      codeVerifier: keyPair.codeVerifier,
      redirectUri: '[INSERT_YOUR_REDIRECT_URI]',
      clientId: '[INSERT_YOUR_CLIENT_ID]',
      //add any header, you deem required.
      header: {},
    );

    if (tokenResponse.refreshToken != null &&
        tokenResponse.accessToken != null) {
      //TODO:save access and refresh token
    }
  } on DioError catch (e) {
    //TODO:handle dio error
  }
}

Simple Example #

To get current users profile.

  _getCurrentUserProfile() async {
  final spotifyUserService = spotifyApiGateway.userClient;
  try{
    final response = await spotifyUserService.getCurrentUsersProfile();
    print('Users name is ${success.displayName}');
  } on DioError catch(e) {
    print('Failed ${failure.message}');
  }
}

Issues and feedback #

Please file issues, bugs, or feature requests in our issue tracker.

Feel free contribute a change to this plugin by opening a pull request.

4
likes
80
pub points
45%
popularity

Publisher

unverified uploader

An api for interacting with Spotify Web Api

Repository (GitHub)
View/report issues

Documentation

API reference

License

unknown (LICENSE)

Dependencies

dio, flutter, flutter_web_auth_2, freezed_annotation, intl, json_annotation, pkce

More

Packages that depend on spotify_flutter