getTrackById method

Future<SpotifyTrack?> getTrackById({
  1. required String id,
})

Implementation

Future<SpotifyTrack?> getTrackById({required String id}) async {
  try {
    final response = await _dio.get('tracks/$id');

    if (response.statusCode == 200) {
      return SpotifyTrack.fromJson(response.data);
    }

    print(
      'Spotify API returned ${response.statusCode}: ${response.statusMessage}',
    );
    return null;
  } on DioException catch (e) {
    _logDioError(e);
    return null;
  } catch (e) {
    print('Unexpected error: $e');
    return null;
  }
}