Tentative ajout image à la playlist.
continuous-integration/drone/push Build is passing Details

messagerie_lucas_test
Félix MIELCAREK 2 years ago
parent 23ec0e3751
commit d2f94d8909

@ -1,7 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dafl_project_flutter"> package="com.example.dafl_project_flutter">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application <application
android:label="Dafl Music" android:label="Dafl Music"
android:name="${applicationName}" android:name="${applicationName}"
@ -20,11 +22,10 @@
to determine the Window background behind the Flutter UI. --> to determine the Window background behind the Flutter UI. -->
<meta-data <meta-data
android:name="io.flutter.embedding.android.NormalTheme" android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme" android:resource="@style/NormalTheme" />
/>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
@ -36,5 +37,6 @@
android:value="2" /> android:value="2" />
</application> </application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />
</manifest> </manifest>

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 KiB

@ -3,8 +3,10 @@ import 'dart:io';
import 'dart:math'; import 'dart:math';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:dafl_project_flutter/main.dart'; import 'package:dafl_project_flutter/main.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:crypto/crypto.dart'; import 'package:crypto/crypto.dart';
import 'package:path_provider/path_provider.dart';
import 'dart:developer' as dev; import 'dart:developer' as dev;
import '../exceptions/api_exception.dart'; import '../exceptions/api_exception.dart';
@ -16,7 +18,7 @@ class Api {
//for web api //for web api
get redirectUri => 'https://daflmusic.000webhostapp.com/callback/'; get redirectUri => 'https://daflmusic.000webhostapp.com/callback/';
final _scopes = final _scopes =
'user-read-playback-state user-read-currently-playing user-read-recently-played playlist-modify-public'; 'user-read-playback-state user-read-currently-playing user-read-recently-played playlist-modify-public ugc-image-upload';
late String _state; late String _state;
dynamic _codeVerifier; dynamic _codeVerifier;
dynamic _codeChallenge; dynamic _codeChallenge;
@ -114,6 +116,7 @@ class Api {
_setResponse(value) { _setResponse(value) {
int sc = value.statusCode; int sc = value.statusCode;
if (sc >= 300) { if (sc >= 300) {
dev.log(value.body.toString());
throw ApiException(sc); throw ApiException(sc);
} }
_response = value; _response = value;
@ -201,7 +204,9 @@ class Api {
if (idPlaylist == null) { if (idPlaylist == null) {
idPlaylist = await _createPlaylist(); idPlaylist = await _createPlaylist();
} else { } else {
if (await _isInPlaylist(idTrack, idPlaylist)) return; if (await _isInPlaylist(idTrack, idPlaylist)) {
return;
}
} }
var token = await _getAccessToken(); var token = await _getAccessToken();
var url = Uri.https('api.spotify.com', 'v1/playlists/$idPlaylist/tracks', var url = Uri.https('api.spotify.com', 'v1/playlists/$idPlaylist/tracks',
@ -231,6 +236,7 @@ class Api {
} }
_createPlaylist() async { _createPlaylist() async {
//create playlist
var idUser = await MyApp.controller.currentUser.getIdSpotify(); var idUser = await MyApp.controller.currentUser.getIdSpotify();
var token = await _getAccessToken(); var token = await _getAccessToken();
var url = Uri.https('api.spotify.com', 'v1/users/$idUser/playlists'); var url = Uri.https('api.spotify.com', 'v1/users/$idUser/playlists');
@ -248,19 +254,28 @@ class Api {
}))); })));
var decodedResponse = jsonDecode(utf8.decode(_response.bodyBytes)) as Map; var decodedResponse = jsonDecode(utf8.decode(_response.bodyBytes)) as Map;
var idPlaylist = decodedResponse['id']; var idPlaylist = decodedResponse['id'];
url = Uri.https('api.spotify.com', 'v1/playlists/playlist_id/images');
String imagePath = 'assets/images/icon_App.png'; //add image : problem in request, API doc does not explain how to give the image
File imagefile = File(imagePath); /*var byteData = await rootBundle.load('assets/images/playlist_icon.jpg');
Uint8List imagebytes = await imagefile.readAsBytes(); var buffer = byteData.buffer.asUint8List();
String base64string = base64.encode(imagebytes); String base64Encode = base64
.encode(buffer)
.replaceAll('+', '-')
.replaceAll('/', '_')
.replaceAll('=', '');
dev.log(jsonEncode(base64Encode).toString());
//dev.log(base64Encode);
//the request should contain a Base64 encoded JPEG image data, maximum payload size is 256 KB
url = Uri.https('api.spotify.com', 'v1/playlists/$idPlaylist/images');
_setResponse(await _client.put(url, _setResponse(await _client.put(url,
headers: <String, String>{ headers: <String, String>{
'Accept': 'application/json', 'Accept': 'application/json',
'Authorization': '$_tokenType $token', 'Authorization': '$_tokenType $token',
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body: base64string)); body: jsonEncode(base64Encode)));
decodedResponse = jsonDecode(utf8.decode(_response.bodyBytes)) as Map; decodedResponse = jsonDecode(utf8.decode(_response.bodyBytes)) as Map;
dev.log(decodedResponse.toString());*/
return idPlaylist; return idPlaylist;
} }

@ -27,8 +27,10 @@ class MyInAppBrowser extends InAppBrowser {
if (url!.origin + url.path == MyApp.api.redirectUri) { if (url!.origin + url.path == MyApp.api.redirectUri) {
try { try {
await MyApp.api.requestUserAuthorization(url); await MyApp.api.requestUserAuthorization(url);
/*var id = await MyApp.api.getCurrentlyPlayingTrack(); var id = await MyApp.api.getCurrentlyPlayingTrack();
await MyApp.api.addToPLaylist(id);*/ //TODO : end the adding of playlist image await MyApp.api
.addToPLaylist(id);
//TODO : end the adding of playlist image
} on ApiException { } on ApiException {
// TODO : add notification to show that an error occured // TODO : add notification to show that an error occured
} finally { } finally {

@ -221,14 +221,12 @@ class CardProvider extends ChangeNotifier {
0, 0,
), ),
blurRadius: 10.0, blurRadius: 10.0,
spreadRadius: 2.0, spreadRadius: 2.0),
),
BoxShadow( BoxShadow(
color: Colors.white.withOpacity(0.3), color: Colors.white.withOpacity(0.3),
offset: const Offset(0.0, 0.0), offset: const Offset(0.0, 0.0),
blurRadius: 0.0, blurRadius: 0.0,
spreadRadius: 0.0, spreadRadius: 0.0)
), //BoxShadow//BoxShadow
], ],
color: const Color(0xFF232123), color: const Color(0xFF232123),
borderRadius: const BorderRadius.only( borderRadius: const BorderRadius.only(

@ -55,6 +55,7 @@ flutter:
uses-material-design: true uses-material-design: true
assets: assets:
- assets/images/ - assets/images/
- assets/images/playlist_icon.jpg
- assets/fonts/ - assets/fonts/
- assets/ - assets/

Loading…
Cancel
Save