From afd2adff5ac3b90d39d46a257d7f4d62943b3283 Mon Sep 17 00:00:00 2001 From: Spark <2666652@gmail.com> Date: Mon, 25 Nov 2024 18:56:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B0=83=E6=95=B4=E4=BE=A7=E8=BE=B9?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E4=B8=BA=E7=82=B9=E8=B5=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/img/like.png | Bin 0 -> 1543 bytes assets/img/unlike.png | Bin 0 -> 1238 bytes lib/api/api_music_list.dart | 16 ++++ lib/models/MusicsListBean.dart | 35 +++++++++ lib/view/home_view.dart | 129 +++++++++++++++------------------ lib/view/rank_view.dart | 29 ++++---- 6 files changed, 124 insertions(+), 85 deletions(-) create mode 100644 assets/img/like.png create mode 100644 assets/img/unlike.png create mode 100644 lib/models/MusicsListBean.dart diff --git a/assets/img/like.png b/assets/img/like.png new file mode 100644 index 0000000000000000000000000000000000000000..ca505ab2bc2512d01ca5f70cc8c9bf79f71caa80 GIT binary patch literal 1543 zcmV+i2Kf1jP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D1)NDlK~!i%)tPHd zQ)d{*&$SoO3SxnRfY72yL9{oZlnN3vW0rkbwq(h+WS{)LW&1SENOYSsne)r8(QKJ< zZf-N`79&w~af(133j$+^P!t3#7lB?V$5(_g&$**MQ7gk__0>ua_!_=T3+OOdThezXeJR1#t}-ThfYbk%NPtd*rKBILS|+o zt5W&#+ZKf9I941O*v2(Czr=NPRPcj?`Gn86o?w_DrO^z~nVEkvM&l*FUVk|uHT400 zTSyj^_Y4o~6irQU1aI8fCkzc4a2y(%4l=p9*VVgse?n~8@&`rJ96s|5Q6z=lUTdJH z=H2Pm*1a$R@%T(g$b^JGMM=p?zr}KVeR_H~j^{8>9*!xot*y#mQ?sA%>MBPcicc*H zsnI-AR#qMp%F4b{uU$KaV`4fGh!Yzc-kQ36`8{D|WD}0V0$mAq&z=vN!ouHahMC5( z1YKQSjh{Zbq`}6GMaiFj_R#W=Wpm(S}G^p?(~iK?!5w+yaXM~0TSlg z+V;vNj^Lq`vwC`7empQBeQzXrH0xY@`)(-krPcTffIK@J8miE93N4BG9#09Z-&xYx zRgO3|mR{)f+EBGnZkH<`Hi|raE+!BL2e-O=dh)2zzCOJ$Je-5`n1CN0&4#+qq9#3_ zMA7e0#Cc30!tDfjucv}&_e1w8u>|;{U7G@USoC=u#|GG$Qmt7tPO8=8IF1RxcMQD8 zD0Ih0B_+9V9urU-Hgtoxi%QMSZKl%FT5ui{&>J^4>kNh#3f=JklaO!|?w@<{xm69B znE0Sgqp4e$lF}>P9&EPTFS15s&1&yv!B1oh3NCIgEv-SvlDtN%?e8-feqpk+Z=vJW z3X_vl*QeK?MZV~GrU5rttyk1$^C{?t25_{hfUkZMM_1_oNwlgepFMV%l#15*pv{QB#fMl?6N$rKR7(#D0VPa4IoJ z9)ap<(&;?PTCJxEl9bx56$56OEiOJa>2Q4Zw9aQUPaXjqK$owg;xJ>e{J3HR0C5H; z(C2g>MjH}N=MYjJq0P$r*SmA)$L#j)XVDUc3Z7vE%H- zlMSc?M-dT~JObLtJ0lLq5jHjl)sIL@kfVC@84!x7j|Wb8>Ft zC?t$t|7X9|dNjjmY{XGi$Rdw0*lbtSCetx!=38+z2P!@Nj>>F42Cu8dQPjvL537zy zR#cpeD=+^7bv-zhfTp<*^3O@9^8$`!K|Xl^{R_z3Y$uft$8l1n@}LYJCsgI-Uqk*w z$bSi=KvsE#A}-Dwuvkv8Ces;_Bstb%IX!7IeWy^XWp6FRx~q(Y2Q4k7DMLfWkCKyb tWfl}P;8<3cP5yZxd)YisVpyIa{sZmjT?{;?EYko0002ovPDHLkV1k?K(`Ntx literal 0 HcmV?d00001 diff --git a/assets/img/unlike.png b/assets/img/unlike.png new file mode 100644 index 0000000000000000000000000000000000000000..6d1fb292b5d8b7e32c4e80561398af5792b41f47 GIT binary patch literal 1238 zcmV;{1S$K8P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D1Zzn|K~!i%)tOC* zRb?2*?^PIUBC`BIYFe~Ns)bk#&cabD24^?S!q7pJ=0xS zSm-QOE%SCss!a3G@#!3Zvv7?$W?>$#z-i|DV6_5E>Ot5=?uYOb%rV!;e*?}lKZKox zViBCh3%y?NBW$6Fy9IAEd;qLkVj1iu?i#jG#GS)z1FM$9axN$F9k|c9lF0c1^Ax0O zu4db(*vcaBeatANYX;4a5_|?*Tjc+Vc^U>a$MF4(tu6Au#;k&PuZiY$#tWATF?Zp% zpPFL(ZDsFUt&$M?Kmdtc`(?dg4l%c&0+R|F19Es#WTc}UKYguh1mjD ztpU4j9dF#L-!o_a zJ&q(HeBWRy-)&kzD?_~`4>!KCwqdIQqMhK+i#v>Bpr*sq)`CVY1>8z5b9SZwe; zB;iGj32>)qJn+KrAwU0o)r!h$6BqkoM z|C`uAEgnE#}Wi~HnhHwByjn9CU=P;cyc2Fev zc_=k-0C|mTpF66*fH)+F<;BKd8NzL9A9|FC*N^m(`2 zo$zxfeCP1J$Z#<)vH~^TytIy*=V|r{O&DKcJkIc{=1r>1|6!}@D$Tw^)B11XeU0Vo zZ)#R;ocV$FdwbN|#?@x?t*eb?Gc+yX<~yDL04FNq#RTIVXaE2J07*qoM6N<$f_0-* AumAu6 literal 0 HcmV?d00001 diff --git a/lib/api/api_music_list.dart b/lib/api/api_music_list.dart index 39fa32b..79e23bd 100644 --- a/lib/api/api_music_list.dart +++ b/lib/api/api_music_list.dart @@ -1,9 +1,11 @@ import 'package:dio/dio.dart'; import '../common_widget/Song_widegt.dart'; +import '../models/MusicsListBean.dart'; import '../models/getMusicList_bean.dart'; import '../models/getRank_bean.dart'; +const String _getMusicList = "http://8.210.250.29:10010/musics/three-random"; const String _getMusic = 'http://8.210.250.29:10010/musics/'; const String _getMusic1 = 'http://8.210.250.29:10010/musics/1'; const String _getMusic2 = 'http://8.210.250.29:10010/musics/2'; @@ -14,6 +16,19 @@ const String _getSongDetail = 'http://8.210.250.29:10010/musics'; class GetMusic { final Dio dio = Dio(); + Future getMusicList({required String Authorization}) async { + Response response = await dio.get( + _getMusicList, + data: { + 'Authorization': Authorization, + }, + options: Options(headers: { + 'Authorization': Authorization, + 'Content-Type': 'application/json;charset=UTF-8' + })); + return MusicsListBean.fromMap(response.data); + } + Future getMusicById({required int id, required String Authorization}) async { print(_getMusic + id.toString()); Response response = await dio.get( @@ -42,6 +57,7 @@ class GetMusic { print(response.data); return MusicListBean.formMap(response.data); } + Future getMusic2({required String Authorization}) async { Response response = await dio.get( _getMusic2, diff --git a/lib/models/MusicsListBean.dart b/lib/models/MusicsListBean.dart new file mode 100644 index 0000000..d0253f6 --- /dev/null +++ b/lib/models/MusicsListBean.dart @@ -0,0 +1,35 @@ +class MusicsListBean { + int? code; + String? msg; + List? data; + + MusicsListBean.fromMap(Map map) { + code = map['code']; + msg = map['msg']; + if (map['data'] != null && map['data'] is List) { + data = (map['data'] as List).map((item) => MusicItem.fromMap(item)).toList(); + } + } +} + +class MusicItem { + int? id; + String? name; + String? coverPath; + String? musicPath; + String? singerName; + String? uploadUserName; + bool? likeOrNot; + bool? collectOrNot; + + MusicItem.fromMap(Map map) { + id = map['id']; + name = map['name']; + coverPath = map['coverPath']; + musicPath = map['musicPath']; + singerName = map['singerName']; + uploadUserName = map['uploadUserName']; + likeOrNot = map['likeOrNot']; + collectOrNot = map['collectOrNot']; + } +} \ No newline at end of file diff --git a/lib/view/home_view.dart b/lib/view/home_view.dart index 31a1214..f8f5867 100644 --- a/lib/view/home_view.dart +++ b/lib/view/home_view.dart @@ -6,11 +6,14 @@ import 'package:music_player_miao/common_widget/app_data.dart'; import 'package:music_player_miao/models/search_bean.dart'; import 'package:music_player_miao/view/comment_view.dart'; import '../../view_model/home_view_model.dart'; +import '../api/api_music_likes.dart'; import '../api/api_music_list.dart'; import '../common/download_manager.dart'; import '../common_widget/Song_widegt.dart'; import '../common_widget/list_cell.dart'; +import '../models/MusicsListBean.dart'; import '../models/getMusicList_bean.dart'; +import '../models/universal_bean.dart'; import 'music_view.dart'; class HomeView extends StatefulWidget { @@ -49,43 +52,22 @@ class _HomeViewState extends State Future _fetchSonglistData() async { try { - MusicListBean bean1 = - await GetMusic().getMusic1(Authorization: AppData().currentToken); - MusicListBean bean2 = - await GetMusic().getMusic2(Authorization: AppData().currentToken); - MusicListBean bean3 = - await GetMusic().getMusic3(Authorization: AppData().currentToken); - + MusicsListBean bean = + await GetMusic().getMusicList(Authorization: AppData().currentToken); setState(() { - selectedSongs = [ - Song( - artistPic: bean1.coverPath!, - title: bean1.name!, - artist: bean1.singerName!, - musicurl: bean1.musicPath!, - pic: bean1.coverPath!, - id: bean1.id!, - likes: bean1.likeOrNot!, - collection: bean1.collectOrNot!), - Song( - artistPic: bean2.coverPath!, - title: bean2.name!, - artist: bean2.singerName!, - musicurl: bean2.musicPath!, - pic: bean2.coverPath!, - id: bean2.id!, - likes: bean2.likeOrNot!, - collection: bean2.collectOrNot!), - Song( - artistPic: bean3.coverPath!, - title: bean3.name!, - artist: bean3.singerName!, - musicurl: bean3.musicPath!, - pic: bean3.coverPath!, - id: bean3.id!, - likes: bean3.likeOrNot!, - collection: bean3.collectOrNot!), - ]; + selectedSongs = []; + for (var data in bean.data!) { + selectedSongs.add(Song( + artistPic: data.coverPath!, + title: data.name!, + artist: data.singerName!, + musicurl: data.musicPath!, + pic: data.coverPath!, + id: data.id!, + likes: data.likeOrNot!, + collection: data.collectOrNot!, + )); + } }); } catch (e) { print('Error occurred while fetching song list: $e'); @@ -415,11 +397,46 @@ class _HomeViewState extends State style: const TextStyle( fontSize: 16, color: Colors.black), ), - trailing: InkWell( - onTap: () { - _bottomSheet(context, index); - }, - child: Image.asset('assets/img/More.png'), + trailing: Padding( + padding: const EdgeInsets.only(right: 16), + child: InkWell( + onTap: () async { + setState(() { + selectedSongs[index].likes = + !selectedSongs[index].likes!; + }); + + UniversalBean response = await LikesApiMusic() + .likesMusic( + musicId: selectedSongs[index].id, + Authorization: + AppData().currentToken); + + if (response.code != 200) { + setState(() { + selectedSongs[index].likes = + !selectedSongs[index].likes!; + }); + } + }, + child: selectedSongs[index].likes! + ? Image.asset( + 'assets/img/like.png', + width: 24, + height: 24, + ) + : ColorFiltered( + colorFilter: ColorFilter.mode( + Colors.grey[700]!, + BlendMode.srcIn, + ), + child: Image.asset( + 'assets/img/unlike.png', + width: 24, + height: 24, + ), + ), + ), ), onTap: () { Navigator.push( @@ -451,36 +468,6 @@ class _HomeViewState extends State const SizedBox( height: 10, ), - - ///精选歌单 - Container( - padding: - const EdgeInsets.only(left: 20, right: 20, top: 5), - child: const Text( - '精选歌单', - style: TextStyle( - fontSize: 20, fontWeight: FontWeight.w500), - ), - ), - const SizedBox( - height: 5, - ), - SizedBox( - height: 180, - child: ListView.builder( - scrollDirection: Axis.horizontal, - shrinkWrap: true, - padding: const EdgeInsets.only(left: 20), - itemCount: homeVM.listArr.length, - itemBuilder: (context, index) { - var sObj = homeVM.listArr[index]; - return ListRow( - sObj: sObj, - onPressed: () {}, - onPressedPlay: () {}, - ); - }), - ), ], ), ), diff --git a/lib/view/rank_view.dart b/lib/view/rank_view.dart index 9a8c633..6c95fe6 100644 --- a/lib/view/rank_view.dart +++ b/lib/view/rank_view.dart @@ -273,20 +273,21 @@ class _RankViewState extends State with AutomaticKeepAliveClientMixin const SizedBox(width: 18), ], ), - IconButton( - onPressed: () { - _bottomSheet(context, index); - }, - icon: Image.asset( - 'assets/img/More.png', - width: 25, - height: 25, - errorBuilder: (context, error, stackTrace) { - print('Error loading image: $error'); - return const Icon(Icons.error, size: 25); - }, - ), - ), + // IconButton( + // onPressed: () { + // _bottomSheet(context, index); + // }, + // icon: Image.asset( + // 'assets/img/More.png', + // width: 25, + // height: 25, + // errorBuilder: (context, error, stackTrace) { + // print('Error loading image: $error'); + // return const Icon(Icons.error, size: 25); + // }, + // ), + // ), + ], ), const SizedBox(height: 10)