spotube/lib/provider/SpotifyDI.dart
Kingkor Roy Tirtho 74ee2aff33 SponsorBlock API support added (cached works too)
Grouped `helpers` folder snippets into appropriate sections
2022-07-19 18:15:12 +06:00

38 lines
1.3 KiB
Dart

import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:spotify/spotify.dart';
import 'package:spotube/components/Home/Home.dart';
import 'package:spotube/models/generated_secrets.dart';
import 'package:spotube/provider/Auth.dart';
import 'package:spotube/utils/primitive_utils.dart';
final spotifyProvider = Provider<SpotifyApi>((ref) {
Auth authState = ref.watch(authProvider);
final anonCred = PrimitiveUtils.getRandomElement(spotifySecrets);
SpotifyApiCredentials apiCredentials = authState.isAnonymous
? SpotifyApiCredentials(
anonCred["clientId"],
anonCred["clientSecret"],
)
: SpotifyApiCredentials(
authState.clientId,
authState.clientSecret,
accessToken: authState.accessToken,
refreshToken: authState.refreshToken,
expiration: authState.expiration,
scopes: spotifyScopes,
);
return SpotifyApi(
apiCredentials,
onCredentialsRefreshed: (credentials) {
authState.setAuthState(
clientId: credentials.clientId,
clientSecret: credentials.clientSecret,
accessToken: credentials.accessToken,
refreshToken: credentials.refreshToken,
expiration: credentials.expiration,
);
},
);
});