From 8d4a9e519ece5d7888cb2e6ad0b9c46075d60ad5 Mon Sep 17 00:00:00 2001 From: wuliwudu <2973566943@qq.com> Date: Wed, 7 Feb 2024 17:22:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E4=BA=86=E9=9F=B3=E4=B9=90?= =?UTF-8?q?=E6=92=AD=E6=94=BE=E7=9A=84=E7=82=B9=E8=B5=9E=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/api/api_music_likes.dart | 18 ------------------ lib/view/music_view.dart | 20 ++++++++++++++------ 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/lib/api/api_music_likes.dart b/lib/api/api_music_likes.dart index c6cd6e5..16571af 100644 --- a/lib/api/api_music_likes.dart +++ b/lib/api/api_music_likes.dart @@ -26,22 +26,4 @@ class LikesApiMusic { print(response.data); return UniversalBean.formMap(response.data); } - - ///取消点赞 - Future 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); - } } diff --git a/lib/view/music_view.dart b/lib/view/music_view.dart index 7715bdd..fdceb16 100644 --- a/lib/view/music_view.dart +++ b/lib/view/music_view.dart @@ -2,9 +2,11 @@ import 'package:flutter/material.dart'; import 'package:get/get.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 'package:audioplayers/audioplayers.dart'; +import '../api/api_music_likes.dart'; import '../api/api_music_list.dart'; import '../common_widget/Song_widegt.dart'; import '../models/getMusicList_bean.dart'; @@ -21,8 +23,6 @@ class MusicView extends StatefulWidget { class _MusicViewState extends State { final homeVM = Get.put(HomeViewModel()); - bool isGoodCommended = AppData().isLikes; - bool isStarCommended = false; bool _isDisposed = false; AppData appData = AppData(); late int currentSongIndex; @@ -31,6 +31,7 @@ class _MusicViewState extends State { List artist = []; List music = []; List likes = []; + List collection = []; Future _fetchSonglistData() async { MusicListBean bean1 = @@ -45,6 +46,7 @@ class _MusicViewState extends State { artist = [bean1.singerName,bean2.singerName,bean3.singerName]; music = [bean1.name,bean2.name,bean3.name]; likes = [bean1.likeOrNot,bean2.likeOrNot,bean3.likeOrNot]; + collection = [bean1.collectOrNot,bean2.collectOrNot,bean3.collectOrNot]; }); } @@ -54,6 +56,7 @@ class _MusicViewState extends State { late Duration _position; late String artistName; late String musicName; late bool likesnot; + late bool collectionsnot; void playerInit() { _audioPlayer = AudioPlayer()..setSourceUrl('${widget.song.musicurl}'); @@ -62,6 +65,7 @@ class _MusicViewState extends State { artistName = '${widget.song.artist}'; musicName = '${widget.song.title}'; likesnot = widget.song.likes; + collectionsnot = widget.song.collection; _audioPlayer.onDurationChanged.listen((Duration d) { _duration = d; @@ -100,6 +104,7 @@ class _MusicViewState extends State { artistName = artist[currentSongIndex]; musicName = music[currentSongIndex]; likesnot = likes[currentSongIndex]; + collectionsnot = collection[currentSongIndex]; _audioPlayer.resume(); } @@ -114,6 +119,7 @@ class _MusicViewState extends State { artistName = artist[currentSongIndex]; musicName = music[currentSongIndex]; likesnot = likes[currentSongIndex]; + collectionsnot = collection[currentSongIndex]; _audioPlayer.resume(); } @@ -248,10 +254,11 @@ class _MusicViewState extends State { Row( children: [ IconButton( - onPressed: () { + onPressed: () async{ + UniversalBean bean1 = + await LikesApiMusic().likesMusic(musicId: currentSongIndex+1, Authorization: AppData().currentToken); setState(() { likesnot = !likesnot; - appData.box.write('isLikes', isGoodCommended); }); }, icon: Image.asset( @@ -265,11 +272,11 @@ class _MusicViewState extends State { IconButton( onPressed: () { setState(() { - isStarCommended = !isStarCommended; + collectionsnot = !collectionsnot; }); }, icon: Image.asset( - isStarCommended + collectionsnot ? "assets/img/music_star.png" : "assets/img/music_star_un.png", width: 29, @@ -487,6 +494,7 @@ class _MusicViewState extends State { artistName = artist[currentSongIndex]; musicName = music[currentSongIndex]; likesnot = likes[currentSongIndex]; + collectionsnot = collection[currentSongIndex]; _audioPlayer.resume(); }); }