diff --git a/android/build.gradle b/android/build.gradle index 96db78a..b12fb14 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,6 +1,13 @@ buildscript { ext.kotlin_version = '1.7.10' repositories { + maven { url 'https://maven.aliyun.com/repository/public/' } + maven { url 'https://maven.aliyun.com/repository/spring/'} + maven { url 'https://maven.aliyun.com/repository/google/'} + maven { url 'https://maven.aliyun.com/repository/gradle-plugin/'} + maven { url 'https://maven.aliyun.com/repository/spring-plugin/'} + maven { url 'https://maven.aliyun.com/repository/grails-core/'} + maven { url 'https://maven.aliyun.com/repository/apache-snapshots/'} google() mavenCentral() } @@ -13,6 +20,13 @@ buildscript { allprojects { repositories { + maven { url 'https://maven.aliyun.com/repository/public/' } + maven { url 'https://maven.aliyun.com/repository/spring/'} + maven { url 'https://maven.aliyun.com/repository/google/'} + maven { url 'https://maven.aliyun.com/repository/gradle-plugin/'} + maven { url 'https://maven.aliyun.com/repository/spring-plugin/'} + maven { url 'https://maven.aliyun.com/repository/grails-core/'} + maven { url 'https://maven.aliyun.com/repository/apache-snapshots/'} google() mavenCentral() mavenCentral() diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 3c472b9..b5228c6 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip +distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-7.5-all.zip diff --git a/lib/api/api_songlist.dart b/lib/api/api_songlist.dart index 387f1b1..78cb797 100644 --- a/lib/api/api_songlist.dart +++ b/lib/api/api_songlist.dart @@ -2,13 +2,41 @@ import 'package:dio/dio.dart'; import 'package:music_player_miao/models/search_bean.dart'; import 'package:music_player_miao/models/songlist_bean.dart'; +import '../models/getAllSongs_bean.dart'; import '../models/universal_bean.dart'; - +import 'package:music_player_miao/models/getMyWorks.dart'; const String _SonglistURL = 'http://flyingpig.fun:10010/songlists'; -///返回歌单 +const String _MyWorksURL = 'http://flyingpig.fun:10010/musics/upload-music'; + + class SonglistApi { final Dio dio = Dio(); + ///获取歌单中所有歌曲 + Future getAllSongs({required int id, required String Authorization}) async { + String urlWithId = 'http://flyingpig.fun:10010/songlist-musics/$id/music-list'; + Response response = await dio.get(urlWithId, + options: Options(headers: { + 'Authorization': Authorization, + 'Content-Type': 'application/json;charset=UTF-8' + })); + print(response.data); + return MyMusicListBean.formMap(response.data); + } + ///获取我的作品 + Future getMyworks({required String Authorization}) async { + Response response = await dio.get(_MyWorksURL, + data: { + 'Authorization': Authorization, + }, + options: Options(headers: { + 'Authorization': Authorization, + 'Content-Type': 'application/json;charset=UTF-8' + })); + print(response.data); + return MyWorks.formMap(response.data); + } + ///返回歌单 Future getSonglist({required String Authorization}) async { Response response = await dio.get(_SonglistURL, data: { diff --git a/lib/main.dart b/lib/main.dart index 95874c1..5140e24 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,9 +1,13 @@ import 'package:flutter/material.dart'; import 'package:music_player_miao/common_widget/app_data.dart'; +import 'package:music_player_miao/view/begin/begin_view.dart'; +import 'package:music_player_miao/view/begin/login_v.dart'; +import 'package:music_player_miao/view/home_view.dart'; import 'package:music_player_miao/view/splash_view.dart'; import 'package:get/get.dart'; import 'dart:io'; import 'package:flutter/services.dart'; +import 'package:music_player_miao/view/user/user_view.dart'; void main(){ WidgetsFlutterBinding.ensureInitialized(); @@ -20,9 +24,14 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { - return const GetMaterialApp( - debugShowCheckedModeBanner: false, - home: SplashView(), + return GetMaterialApp( + title: 'Flutter Demo', + initialRoute: '/login', // 初始路由 + routes: { + '/': (context) => HomeView(), // 定义首页路由 + '/user': (context) => UserView(), + '/login' : (context) => BeginView()// 定义UserView的路由 + }, ); } } diff --git a/lib/models/getAllSongs_bean.dart b/lib/models/getAllSongs_bean.dart new file mode 100644 index 0000000..c947770 --- /dev/null +++ b/lib/models/getAllSongs_bean.dart @@ -0,0 +1,43 @@ +class MyMusicListBean { + int? code; + String? msg; + List? data; + + MyMusicListBean.formMap(Map map) { + code = map['code']; + msg = map['msg']; + if (map['data'] is! List) return; + + data = (map['data'] as List) + .map((item) => DataBean._formMap(item)) + .toList(); + } +} + +class DataBean { + int? songlistId; + SongDetails? musicDetail; // 修改为单个SongDetails对象 + + DataBean._formMap(Map map) { + songlistId = map['songlistId']; + musicDetail = SongDetails._formMap(map['musicDetail']); // 直接处理单个对象 + } +} + +class SongDetails { + int? id; + String? name; + String? coverPath; + String? musicPath; + String? singerName; + String? uploadUserName; + + SongDetails._formMap(Map map) { + id = map['id']; + name = map['name']; + coverPath = map['coverPath']; + musicPath = map['musicPath']; + singerName = map['singerName']; + uploadUserName = map['uploadUserName']; + } +} \ No newline at end of file diff --git a/lib/models/getMusicList_bean.dart b/lib/models/getMusicList_bean.dart index 2c419ac..1e1a8f2 100644 --- a/lib/models/getMusicList_bean.dart +++ b/lib/models/getMusicList_bean.dart @@ -9,6 +9,8 @@ class MusicListBean { String? uploadUserName; bool? likeOrNot; bool? collectOrNot; + + MusicListBean.formMap(Map map){ code = map['code']; msg= map['msg']; diff --git a/lib/models/getMyWorks.dart b/lib/models/getMyWorks.dart new file mode 100644 index 0000000..fbdef71 --- /dev/null +++ b/lib/models/getMyWorks.dart @@ -0,0 +1,34 @@ +class MyWorks { + int? code; + String? msg; + List? data; + + MyWorks.formMap(Map map) { + code = map['code']; + msg = map['msg']; + if (map['data'] == null) return; + + List? dataList = map['data']; + if (dataList == null) return; + + data = dataList + .map((item) => DataBean._formMap(item)) + .toList(); + } +} + +class DataBean { + int? id; + String? name; + String? coverPath; + String? musicPath; + String? singerName; + + DataBean._formMap(Map map) { + id = map['id']; + name = map['name']; + coverPath = map['coverPath']; + musicPath = map['musicPath']; + singerName = map['singerName']; + } +} diff --git a/lib/view/user/my_music_view.dart b/lib/view/user/my_music_view.dart index 7302124..099d53c 100644 --- a/lib/view/user/my_music_view.dart +++ b/lib/view/user/my_music_view.dart @@ -1,22 +1,94 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import '../../common_widget/app_data.dart'; +import '../../models/getAllSongs_bean.dart'; import '../../view_model/home_view_model.dart'; +import '../../api/api_songlist.dart'; +import '../../api/api_songlist.dart'; -class MyMusicView extends StatefulWidget { - const MyMusicView({super.key}); +List flatten(Iterable> iterable) { + return iterable.expand((inner) => inner).toList(); +} +class MyMusicView extends StatefulWidget { + final int? songlistIdd; + const MyMusicView({Key? key, this.songlistIdd}) : super(key: key); @override State createState() => _MyMusicViewState(); } class _MyMusicViewState extends State { + int songsNum = 0; + List songlistId =[]; + List musicDetail = []; + List name = []; + List coverPath = []; + List musicPath = []; + List singerName =[]; + List uploadUserName = []; + final listVM = Get.put(HomeViewModel()); bool _isSelectMode = false; final List _mySongListSelections = List.generate(2, (index) => false); List _selectedItems = List.generate(10, (index) => false); + +//修改从这开始 + @override + void initState() { + super.initState(); + if (widget.songlistIdd != null) { + _fetchMyWorksData(); + } else { + // 处理 songlistIdd 为 null 的情况,例如显示错误消息或不执行数据获取 + print('Songlist ID is null, cannot fetch data.'); + } + } + + ///获取我的作品 + Future _fetchMyWorksData() async { + try { + MyMusicListBean bean2 = await SonglistApi().getAllSongs( + id: widget.songlistIdd!, + Authorization: AppData().currentToken, + ); + + setState(() { + // 初始化列表 + name = []; + coverPath = []; + musicPath = []; + singerName = []; + songlistId = []; + + // 遍历每个DataBean对象 + bean2.data?.forEach((dataBean) { + // 提取songlistId + songlistId.add(dataBean.songlistId); + + // 提取musicDetail对象 + SongDetails songDetails = dataBean.musicDetail!; + + // 添加歌曲信息到列表 + name.add(songDetails.name); + coverPath.add(songDetails.coverPath); + musicPath.add(songDetails.musicPath); + singerName.add(songDetails.singerName); + }); + + songsNum = name.length; // 歌曲数量 + print('赋值开始'); + print('赋值结束'); + }); + } catch (error) { + print('Error fetching myworks data: $error'); + } + } + //在这里结束 + + void _toggleSelectMode() { setState(() { _isSelectMode = !_isSelectMode; @@ -232,8 +304,10 @@ class _MyMusicViewState extends State { ], ), Expanded( - child: ListView.builder( - itemCount: 10, + child: songsNum == 0 + ? Center(child: Text('该歌单为空')) // 如果没有作品,显示提示文本 + : ListView.builder( + itemCount: songsNum, itemBuilder: (BuildContext context, int index) { return Container( padding: const EdgeInsets.symmetric(vertical: 5.0), @@ -249,8 +323,11 @@ class _MyMusicViewState extends State { shape: const CircleBorder(), activeColor: const Color(0xff429482), ) - : null, - title: Text('歌曲名 $index - 歌手'), + : CircleAvatar( + backgroundImage: NetworkImage(coverPath[index]), // 假设封面路径是网络资源 + radius: 25, + ), + title: Text('${name[index]} - ${singerName[index]}'), // 显示歌曲名和歌手名 trailing: _isSelectMode ? null : IconButton( @@ -444,3 +521,6 @@ class _MyMusicViewState extends State { ); } } + + + diff --git a/lib/view/user/my_work_view.dart b/lib/view/user/my_work_view.dart index 7b67e44..327effb 100644 --- a/lib/view/user/my_work_view.dart +++ b/lib/view/user/my_work_view.dart @@ -1,6 +1,9 @@ - import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:music_player_miao/common_widget/Song_widegt.dart'; +import '../../api/api_songlist.dart'; +import '../../common_widget/app_data.dart'; +import '../../models/getMyWorks.dart'; import '../../view_model/home_view_model.dart'; class MyWorkView extends StatefulWidget { @@ -11,6 +14,12 @@ class MyWorkView extends StatefulWidget { } class _MyWorkViewState extends State { + int MyWorkCount = 0; + List MyWorkNames = []; + List Songid = []; + List coverPath = []; + List musicPath = []; + List singerName = []; final listVM = Get.put(HomeViewModel()); bool _isSelectMode = false; @@ -18,6 +27,37 @@ class _MyWorkViewState extends State { List _mySongListSelections = List.generate(2, (index) => false); List _selectedItems = List.generate(10, (index) => false); +//从这里开始是我要修改的请求接口 + @override + void initState() { + super.initState(); + print('初始化正常'); + _fetchMyWorksData(); + } + + ///获取我的作品 + Future _fetchMyWorksData() async { + try { + MyWorks bean2 = await SonglistApi().getMyworks( + Authorization: AppData().currentToken, + ); + + setState(() { + MyWorkNames = bean2.data!.map((data) => data.name!).toList(); + Songid = bean2.data!.map((data) => data.id!).toList(); + coverPath = bean2.data!.map((data) => data.coverPath!).toList(); + musicPath = bean2.data!.map((data) => data.musicPath!).toList(); + singerName = bean2.data!.map((data) => data.singerName!).toList(); + print('赋值开始'); + MyWorkCount = MyWorkNames.length; + print('赋值结束'); + }); + } catch (error) { + print('Error fetching myworks data: $error'); + } + } + //在这里结束 + void _toggleSelectMode() { setState(() { _isSelectMode = !_isSelectMode; @@ -248,8 +288,10 @@ class _MyWorkViewState extends State { ], ), Expanded( - child: ListView.builder( - itemCount: 10, + child: MyWorkCount == 0 + ? Center(child: Text('你还没有作品')) // 如果没有作品,显示提示文本 + : ListView.builder( + itemCount: MyWorkCount, itemBuilder: (BuildContext context, int index) { return Container( padding: const EdgeInsets.symmetric(vertical: 5.0), @@ -265,8 +307,11 @@ class _MyWorkViewState extends State { shape: const CircleBorder(), activeColor: const Color(0xff429482), ) - : null, - title: Text('歌曲名 $index - 歌手'), + : CircleAvatar( + backgroundImage: NetworkImage(coverPath[index]), // 假设封面路径是网络资源 + radius: 25, + ), + title: Text('${MyWorkNames[index]} - ${singerName[index]}'), // 显示歌曲名和歌手名 trailing: _isSelectMode ? null : IconButton( @@ -459,4 +504,4 @@ class _MyWorkViewState extends State { ); } -} +} \ No newline at end of file diff --git a/lib/view/user/user_view.dart b/lib/view/user/user_view.dart index be2ef41..04288db 100644 --- a/lib/view/user/user_view.dart +++ b/lib/view/user/user_view.dart @@ -27,9 +27,9 @@ class UserView extends StatefulWidget { class _UserViewState extends State { final homeVM = Get.put(HomeViewModel()); final TextEditingController _controller = TextEditingController(); - int playlistCount = 2; + int playlistCount = 0; List playlistNames = []; - List playlistid = []; + List playlistid = []; int downloadCount = 0; String avatar = AppData().currentAvatar; String username = AppData().currentUsername; @@ -51,7 +51,7 @@ class _UserViewState extends State { setState(() { playlistNames = bean2.data!.map((data) => data.name!).toList(); - playlistid = bean2.data!.map((data) => data.id!).toList(); + playlistid = bean2.data!.map((data) => data.id!).toList(); // 确保这里的id是int类型 playlistCount = playlistNames.length; }); } catch (error) { @@ -116,6 +116,8 @@ class _UserViewState extends State { Container( padding: const EdgeInsets.only( left: 15, right: 15, top: 20, bottom: 20), + + //我的收藏 child: Column( mainAxisAlignment: MainAxisAlignment.start, children: [ @@ -152,6 +154,8 @@ class _UserViewState extends State { const SizedBox( height: 10, ), + + //我的收藏和本地下载分界 InkWell( onTap: () async { final result = await Get.to(const MyDownloadView()); @@ -220,72 +224,43 @@ class _UserViewState extends State { ], ), Container( - padding: const EdgeInsets.only( - left: 15, right: 15, top: 10, bottom: 5), - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - InkWell( - onTap: () {}, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Image.asset("assets/img/artist_pic.png"), - const Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - "我的收藏", - style: TextStyle(fontSize: 20), - ), - Text( - "19首", - style: TextStyle(fontSize: 16), - ), - ], - ), - const SizedBox( - width: 80, - ), - Image.asset( - "assets/img/user_next.png", - ) - ], - ), - ), - const SizedBox( - height: 10, - ), - InkWell( - onTap: () {}, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Image.asset("assets/img/artist_pic.png"), - const Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - "本地下载", - style: TextStyle(fontSize: 20), - ), - Text( - "19首", - style: TextStyle(fontSize: 16), - ), - ], - ), - const SizedBox( - width: 80, - ), - Image.asset( - "assets/img/user_next.png", - ) - ], - ), + padding: const EdgeInsets.only(left: 15, right: 15, top: 10, bottom: 5), + child: ListView.builder( + shrinkWrap: true, // 使得ListView适应内容高度 + itemCount: playlistNames.length, // 根据歌单数量动态设置itemCount + itemBuilder: (context, index) { + return InkWell( + onTap: () { + print('点击成功'); + Get.to(MyMusicView(songlistIdd: playlistid[index])); + // 点击歌单时的回调,可以导航到歌单详情页 + //待添加 + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Image.asset("assets/img/artist_pic.png"), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + playlistNames[index], // 动态显示歌单名称 + style: TextStyle(fontSize: 20), + ), + Text( + '$playlistCount首', // 动态显示歌曲数量 + style: TextStyle(fontSize: 16), + ), + ], + ), + const SizedBox(width: 80), + Image.asset("assets/img/user_next.png"), + ], ), - ], - )), + ); + }, + ), + ), InkWell( onTap: () { Get.to(const MyMusicView()); @@ -469,7 +444,6 @@ class _UserViewState extends State { ); } - ///弹出框--添加歌单 void _showAddPlaylistDialog() { _controller.clear();