Ajout de la classe track et de la récupération des informations d'un track
continuous-integration/drone/push Build is passing Details

messagerie_lucas_test
Félix MIELCAREK 2 years ago
parent 6deb3b96de
commit 0658b94412

@ -2,6 +2,8 @@ import 'dart:convert';
import 'dart:math';
import 'package:http/http.dart' as http;
import 'track.dart';
class Api {
//from dashboard
final _clientId = '7ceb49d874b9404492246027e4d68cf8';
@ -99,15 +101,30 @@ class Api {
//functional methods
getCurrentlyPlayingTrack() async {
Future<String> getCurrentlyPlayingTrack() async {
var url = Uri.https('api.spotify.com', 'v1/me/player/currently-playing');
var token = await _getToken();
var response = await _client.get(url, headers: <String, String>{
'Authorization': '$_tokenType $token',
'Content-Type': 'application/json'
});
// Implement treatment of data's
print(response.statusCode);
var decodedResponse = jsonDecode(utf8.decode(response.bodyBytes)) as Map;
return decodedResponse['item']['id'];
}
Future<Track> getTrackInfo(String id) async {
var url = Uri.https('api.spotify.com', 'v1/tracks/$id');
var token = await _getToken();
var response = await _client.get(url, headers: <String, String>{
'Authorization': '$_tokenType $token',
'Content-Type': 'application/json'
});
var decodedResponse = jsonDecode(utf8.decode(response.bodyBytes)) as Map;
print(decodedResponse['item']['href']);
return Track(
decodedResponse['artists'][0]['name'],
decodedResponse['name'],
decodedResponse['album']['images']
[decodedResponse['album']['images'].length - 1]['url']);
}
}

@ -1,4 +1,5 @@
import 'dart:io';
import 'package:dafl_project_flutter/api/track.dart';
import 'package:dafl_project_flutter/main.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
@ -25,7 +26,6 @@ class MyInAppBrowser extends InAppBrowser {
Future onLoadStart(url) async {
if (url!.origin + url.path == MyApp.api.redirectUri) {
await MyApp.api.requestUserAuthorization(url);
await MyApp.api.getCurrentlyPlayingTrack();
close();
}
}

@ -0,0 +1,11 @@
class Track {
final String _artist;
final String _name;
final String _albumImage;
Track(this._artist, this._name, this._albumImage);
String get artist => _artist;
String get name => _name;
String get albumImage => _albumImage;
}
Loading…
Cancel
Save