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

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 KiB

@ -3,8 +3,10 @@ import 'dart:io';
import 'dart:math';
import 'dart:typed_data';
import 'package:dafl_project_flutter/main.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
import 'package:crypto/crypto.dart';
import 'package:path_provider/path_provider.dart';
import 'dart:developer' as dev;
import '../exceptions/api_exception.dart';
@ -16,7 +18,7 @@ class Api {
//for web api
get redirectUri => 'https://daflmusic.000webhostapp.com/callback/';
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;
dynamic _codeVerifier;
dynamic _codeChallenge;
@ -114,6 +116,7 @@ class Api {
_setResponse(value) {
int sc = value.statusCode;
if (sc >= 300) {
dev.log(value.body.toString());
throw ApiException(sc);
}
_response = value;
@ -201,7 +204,9 @@ class Api {
if (idPlaylist == null) {
idPlaylist = await _createPlaylist();
} else {
if (await _isInPlaylist(idTrack, idPlaylist)) return;
if (await _isInPlaylist(idTrack, idPlaylist)) {
return;
}
}
var token = await _getAccessToken();
var url = Uri.https('api.spotify.com', 'v1/playlists/$idPlaylist/tracks',
@ -231,6 +236,7 @@ class Api {
}
_createPlaylist() async {
//create playlist
var idUser = await MyApp.controller.currentUser.getIdSpotify();
var token = await _getAccessToken();
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 idPlaylist = decodedResponse['id'];
url = Uri.https('api.spotify.com', 'v1/playlists/playlist_id/images');
String imagePath = 'assets/images/icon_App.png';
File imagefile = File(imagePath);
Uint8List imagebytes = await imagefile.readAsBytes();
String base64string = base64.encode(imagebytes);
//add image : problem in request, API doc does not explain how to give the image
/*var byteData = await rootBundle.load('assets/images/playlist_icon.jpg');
var buffer = byteData.buffer.asUint8List();
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,
headers: <String, String>{
'Accept': 'application/json',
'Authorization': '$_tokenType $token',
'Content-Type': 'application/json'
},
body: base64string));
body: jsonEncode(base64Encode)));
decodedResponse = jsonDecode(utf8.decode(_response.bodyBytes)) as Map;
dev.log(decodedResponse.toString());*/
return idPlaylist;
}

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

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

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

Loading…
Cancel
Save