对接了音乐播放的点赞部分

dev
wuliwudu 10 months ago
parent 73c9190727
commit 8d4a9e519e

@ -26,22 +26,4 @@ class LikesApiMusic {
print(response.data); print(response.data);
return UniversalBean.formMap(response.data); return UniversalBean.formMap(response.data);
} }
///
Future<UniversalBean> unlikesMusic({
required int musicId,
required String Authorization,
}) async {
Response response = await dio.post(_LikesURL,
data: {
"Authorization": Authorization,
},
queryParameters: {'musicId': musicId},
options: Options(headers: {
'Authorization': Authorization,
'Content-Type': 'application/json;charset=UTF-8'
}));
print(response.data);
return UniversalBean.formMap(response.data);
}
} }

@ -2,9 +2,11 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:music_player_miao/common_widget/app_data.dart'; import 'package:music_player_miao/common_widget/app_data.dart';
import 'package:music_player_miao/models/universal_bean.dart';
import '../../view_model/home_view_model.dart'; import '../../view_model/home_view_model.dart';
import 'package:audioplayers/audioplayers.dart'; import 'package:audioplayers/audioplayers.dart';
import '../api/api_music_likes.dart';
import '../api/api_music_list.dart'; import '../api/api_music_list.dart';
import '../common_widget/Song_widegt.dart'; import '../common_widget/Song_widegt.dart';
import '../models/getMusicList_bean.dart'; import '../models/getMusicList_bean.dart';
@ -21,8 +23,6 @@ class MusicView extends StatefulWidget {
class _MusicViewState extends State<MusicView> { class _MusicViewState extends State<MusicView> {
final homeVM = Get.put(HomeViewModel()); final homeVM = Get.put(HomeViewModel());
bool isGoodCommended = AppData().isLikes;
bool isStarCommended = false;
bool _isDisposed = false; bool _isDisposed = false;
AppData appData = AppData(); AppData appData = AppData();
late int currentSongIndex; late int currentSongIndex;
@ -31,6 +31,7 @@ class _MusicViewState extends State<MusicView> {
List artist = []; List artist = [];
List music = []; List music = [];
List likes = []; List likes = [];
List collection = [];
Future<void> _fetchSonglistData() async { Future<void> _fetchSonglistData() async {
MusicListBean bean1 = MusicListBean bean1 =
@ -45,6 +46,7 @@ class _MusicViewState extends State<MusicView> {
artist = [bean1.singerName,bean2.singerName,bean3.singerName]; artist = [bean1.singerName,bean2.singerName,bean3.singerName];
music = [bean1.name,bean2.name,bean3.name]; music = [bean1.name,bean2.name,bean3.name];
likes = [bean1.likeOrNot,bean2.likeOrNot,bean3.likeOrNot]; likes = [bean1.likeOrNot,bean2.likeOrNot,bean3.likeOrNot];
collection = [bean1.collectOrNot,bean2.collectOrNot,bean3.collectOrNot];
}); });
} }
@ -54,6 +56,7 @@ class _MusicViewState extends State<MusicView> {
late Duration _position; late String artistName; late Duration _position; late String artistName;
late String musicName; late String musicName;
late bool likesnot; late bool likesnot;
late bool collectionsnot;
void playerInit() { void playerInit() {
_audioPlayer = AudioPlayer()..setSourceUrl('${widget.song.musicurl}'); _audioPlayer = AudioPlayer()..setSourceUrl('${widget.song.musicurl}');
@ -62,6 +65,7 @@ class _MusicViewState extends State<MusicView> {
artistName = '${widget.song.artist}'; artistName = '${widget.song.artist}';
musicName = '${widget.song.title}'; musicName = '${widget.song.title}';
likesnot = widget.song.likes; likesnot = widget.song.likes;
collectionsnot = widget.song.collection;
_audioPlayer.onDurationChanged.listen((Duration d) { _audioPlayer.onDurationChanged.listen((Duration d) {
_duration = d; _duration = d;
@ -100,6 +104,7 @@ class _MusicViewState extends State<MusicView> {
artistName = artist[currentSongIndex]; artistName = artist[currentSongIndex];
musicName = music[currentSongIndex]; musicName = music[currentSongIndex];
likesnot = likes[currentSongIndex]; likesnot = likes[currentSongIndex];
collectionsnot = collection[currentSongIndex];
_audioPlayer.resume(); _audioPlayer.resume();
} }
@ -114,6 +119,7 @@ class _MusicViewState extends State<MusicView> {
artistName = artist[currentSongIndex]; artistName = artist[currentSongIndex];
musicName = music[currentSongIndex]; musicName = music[currentSongIndex];
likesnot = likes[currentSongIndex]; likesnot = likes[currentSongIndex];
collectionsnot = collection[currentSongIndex];
_audioPlayer.resume(); _audioPlayer.resume();
} }
@ -248,10 +254,11 @@ class _MusicViewState extends State<MusicView> {
Row( Row(
children: [ children: [
IconButton( IconButton(
onPressed: () { onPressed: () async{
UniversalBean bean1 =
await LikesApiMusic().likesMusic(musicId: currentSongIndex+1, Authorization: AppData().currentToken);
setState(() { setState(() {
likesnot = !likesnot; likesnot = !likesnot;
appData.box.write('isLikes', isGoodCommended);
}); });
}, },
icon: Image.asset( icon: Image.asset(
@ -265,11 +272,11 @@ class _MusicViewState extends State<MusicView> {
IconButton( IconButton(
onPressed: () { onPressed: () {
setState(() { setState(() {
isStarCommended = !isStarCommended; collectionsnot = !collectionsnot;
}); });
}, },
icon: Image.asset( icon: Image.asset(
isStarCommended collectionsnot
? "assets/img/music_star.png" ? "assets/img/music_star.png"
: "assets/img/music_star_un.png", : "assets/img/music_star_un.png",
width: 29, width: 29,
@ -487,6 +494,7 @@ class _MusicViewState extends State<MusicView> {
artistName = artist[currentSongIndex]; artistName = artist[currentSongIndex];
musicName = music[currentSongIndex]; musicName = music[currentSongIndex];
likesnot = likes[currentSongIndex]; likesnot = likes[currentSongIndex];
collectionsnot = collection[currentSongIndex];
_audioPlayer.resume(); _audioPlayer.resume();
}); });
} }

Loading…
Cancel
Save