Merge remote-tracking branch 'refs/remotes/origin/liu'

# Conflicts:
#	.vscode/settings.json
#	lib/view/user/user_view.dart
#	pubspec.lock
chen
Spark 8 months ago
commit a2140cdf6d

@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "windows-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "C:/mingw64/bin/gcc.exe",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "windows-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}

@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": true,
"cwd": "e:/Flutter/MusicAPP/MTMusic/linux/flutter",
"program": "e:/Flutter/MusicAPP/MTMusic/linux/flutter/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

@ -0,0 +1,32 @@
import 'package:dio/dio.dart';
import '../models/getLikeList_bean.dart';
const String _LikesListURL = 'http://8.210.250.29:10010/likes/user-like-list';
class LikesListApi {
final Dio dio = Dio();
///
Future<LikeListBean> getUserLikesList({
required String Authorization,
}) async {
try {
Response response = await dio.get(
_LikesListURL,
options: Options(
headers: {
'Authorization': Authorization,
'Content-Type': 'application/json;charset=UTF-8'
}
),
);
print('点赞列表响应数据: ${response.data}');
return LikeListBean.formMap(response.data);
} catch (e) {
print('获取点赞列表失败: $e');
rethrow;
}
}
}

@ -0,0 +1,51 @@
class LikeListBean {
int? code;
String? msg;
List<LikeListData>? data;
LikeListBean.formMap(Map map) {
code = map['code'];
msg = map['msg'];
if (map['data'] is! List) return;
data = (map['data'] as List)
.map((item) => LikeListData._formMap(item))
.toList();
}
}
class LikeListData {
int? id;
String? name;
String? coverPath;
String? musicPath;
String? singerName;
String? uploadUserName;
bool? likes;
bool? collection;
LikeListData._formMap(Map map) {
id = map['id'];
name = map['name'];
coverPath = map['coverPath'];
musicPath = map['musicPath'];
singerName = map['singerName'];
uploadUserName = map['uploadUserName'];
likes = map['likes'];
collection = map['collection'];
}
// Map,
Map<String, dynamic> toJson() {
return {
'id': id,
'name': name,
'coverPath': coverPath,
'musicPath': musicPath,
'singerName': singerName,
'uploadUserName': uploadUserName,
'likes': likes,
'collection': collection,
};
}
}

@ -15,6 +15,9 @@ import '../models/MusicsListBean.dart';
import '../models/getMusicList_bean.dart';
import '../models/universal_bean.dart';
import 'music_view.dart';
import '../api/api_collection.dart';
import '../api/api_music_likes.dart';
import '../models/universal_bean.dart';
class HomeView extends StatefulWidget {
const HomeView({super.key});
@ -94,7 +97,7 @@ class _HomeViewState extends State<HomeView>
//
if (bean.code == 200 && bean.data != null) {
//
// <EFBFBD><EFBFBD><EFBFBD>
List<Future<Song?>> songDetailsFutures = [];
// id
@ -458,16 +461,15 @@ class _HomeViewState extends State<HomeView>
builder: (context) => MusicView(
songList: selectedSongs,
initialSongIndex: index,
onSongStatusChanged:
(index, isCollected, isLiked) {
onSongStatusChanged: (index, isCollected, isLiked) {
setState(() {
selectedSongs[index].collection =
isCollected;
selectedSongs[index].collection = isCollected;
selectedSongs[index].likes = isLiked;
downloadManager.updateSongInfo(
selectedSongs[index].id,
isCollected,
isLiked);
selectedSongs[index].id,
isCollected,
isLiked
);
});
},
),
@ -502,19 +504,20 @@ class _HomeViewState extends State<HomeView>
borderRadius: BorderRadius.vertical(top: Radius.circular(30)),
),
builder: (context) => StatefulBuilder(
// 使StatefulBuilder便
builder: (context, setState) {
bool likesnot = false; //
//
bool likesnot = selectedSongs[index].likes ?? false;
bool collectionsnot = selectedSongs[index].collection ?? false;
return Container(
height: 150,
padding: const EdgeInsets.only(top: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
//
Column(
children: [
IconButton(
@ -525,6 +528,8 @@ class _HomeViewState extends State<HomeView>
const Text("加入歌单"),
],
),
//
Column(
children: [
IconButton(
@ -535,37 +540,122 @@ class _HomeViewState extends State<HomeView>
const Text("下载"),
],
),
//
Column(
children: [
IconButton(
onPressed: () {},
icon: Image.asset("assets/img/list_collection.png"),
iconSize: 60,
onPressed: () async {
// 1. UI
setState(() {
collectionsnot = !collectionsnot;
selectedSongs[index].collection = collectionsnot;
});
// 2. API
UniversalBean response = await CollectionApiMusic().addCollection(
musicId: selectedSongs[index].id,
Authorization: AppData().currentToken,
);
// 3. API
if (response.code != 200) {
// 3.1 API
setState(() {
collectionsnot = !collectionsnot;
selectedSongs[index].collection = collectionsnot;
});
} else {
// 3.2 API
downloadManager.updateSongInfo(
selectedSongs[index].id, // ID
collectionsnot, //
selectedSongs[index].likes ?? false //
);
}
},
icon: SizedBox(
width: 60,
height: 60,
child: Image.asset(
//
collectionsnot
? "assets/img/list_collection.png" //
: "assets/img/list_collection_un.png" //
),
),
),
const Text("收藏"),
],
),
//
Column(
children: [
IconButton(
onPressed: () {},
icon: Image.asset("assets/img/list_good.png"),
iconSize: 60,
onPressed: () async {
// 1. UI
setState(() {
likesnot = !likesnot;
selectedSongs[index].likes = likesnot;
});
// 2. API
UniversalBean response = await LikesApiMusic().likesMusic(
musicId: selectedSongs[index].id,
Authorization: AppData().currentToken,
);
// 3. API
if (response.code != 200) {
// 3.1 API
setState(() {
likesnot = !likesnot;
selectedSongs[index].likes = likesnot;
});
} else {
// 3.2 API
downloadManager.updateSongInfo(
selectedSongs[index].id, // ID
selectedSongs[index].collection ?? false, //
likesnot //
);
}
},
icon: SizedBox(
width: 60,
height: 60,
child: Image.asset(
//
likesnot
? "assets/img/list_good.png" //
: "assets/img/list_good_un.png" //
),
),
),
const Text("点赞")
const Text("点赞"),
],
),
//
Column(
children: [
IconButton(
onPressed: () {
//
Navigator.pop(context);
// Get.to(() =>
// CommentView(
// id:,
// song:,
// singer:,
// ));
//
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CommentView(
id: selectedSongs[index].id,
song: selectedSongs[index].title,
singer: selectedSongs[index].artist,
cover: selectedSongs[index].artistPic,
),
),
);
},
icon: Image.asset("assets/img/list_comment.png"),
iconSize: 60,

@ -7,6 +7,12 @@ import '../models/getRank_bean.dart';
import '../view_model/rank_view_model.dart';
import 'music_view.dart';
import '../common_widget/Song_widegt.dart';
import '../api/api_collection.dart';
import '../api/api_music_likes.dart';
import '../api/api_music_list.dart';
import '../models/universal_bean.dart';
import 'comment_view.dart';
import '../models/getMusicList_bean.dart';
class RankView extends StatefulWidget {
const RankView({super.key});
@ -321,77 +327,167 @@ class _RankViewState extends State<RankView> with AutomaticKeepAliveClientMixin
Future _bottomSheet(BuildContext context, int index) {
return showModalBottomSheet(
context: context,
backgroundColor: Colors.white,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(30))
),
builder: (context) => Container(
height: 150,
padding: const EdgeInsets.only(top: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Column(
children: [
IconButton(
onPressed: (){},
icon: Image.asset("assets/img/list_add.png"),
iconSize: 60,
),
const Text("加入歌单")
],
),
Column(
children: [
IconButton(
onPressed: (){},
icon: Image.asset("assets/img/list_download.png"),
iconSize: 60,
),
const Text("下载")
],
),
Column(
children: [
IconButton(
onPressed: (){},
icon: Image.asset("assets/img/list_collection.png"),
iconSize: 60,
),
const Text("收藏")
],
),
Column(
children: [
IconButton(
onPressed: (){},
icon: Image.asset("assets/img/list_good.png"),
iconSize: 60,
),
const Text("点赞")
],
),
Column(
children: [
IconButton(
onPressed: (){
Navigator.pop(context);
},
icon: Image.asset("assets/img/list_comment.png"),
iconSize: 60,
),
const Text("评论")
],
),
],
),
],
),
)
context: context,
backgroundColor: Colors.white,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(30)),
),
builder: (context) => StatefulBuilder(
builder: (context, setState) {
//
bool likesnot = songs[index].likes ?? false;
bool collectionsnot = songs[index].collection ?? false;
return Container(
height: 150,
padding: const EdgeInsets.only(top: 20),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Column(
children: [
IconButton(
onPressed: (){},
icon: Image.asset("assets/img/list_add.png"),
iconSize: 60,
),
const Text("加入歌单")
],
),
Column(
children: [
IconButton(
onPressed: (){},
icon: Image.asset("assets/img/list_download.png"),
iconSize: 60,
),
const Text("下载")
],
),
Column(
children: [
IconButton(
onPressed: () async {
// 1. UI
setState(() {
collectionsnot = !collectionsnot;
songs[index].collection = collectionsnot;
});
// 2. API
UniversalBean response = await CollectionApiMusic().addCollection(
musicId: songs[index].id,
Authorization: AppData().currentToken,
);
// 3. API
if (response.code != 200) {
// API
setState(() {
collectionsnot = !collectionsnot;
songs[index].collection = collectionsnot;
});
} else {
// 4. API
downloadManager.updateSongInfo(
songs[index].id, // ID
collectionsnot, //
songs[index].likes ?? false //
);
}
},
icon: SizedBox(
width: 60,
height: 60,
child: Image.asset(
//
collectionsnot
? "assets/img/list_collection.png" //
: "assets/img/list_collection_un.png" //
),
),
),
const Text("收藏"),
],
),
Column(
children: [
IconButton(
onPressed: () async {
// 1. UI
setState(() {
likesnot = !likesnot;
songs[index].likes = likesnot;
});
// 2. API
UniversalBean response = await LikesApiMusic().likesMusic(
musicId: songs[index].id,
Authorization: AppData().currentToken,
);
// 3. API
if (response.code != 200) {
// API
setState(() {
likesnot = !likesnot;
songs[index].likes = likesnot;
});
} else {
// 4. API
downloadManager.updateSongInfo(
songs[index].id, // ID
songs[index].collection ?? false, //
likesnot //
);
}
},
icon: SizedBox(
width: 60,
height: 60,
child: Image.asset(
//
likesnot
? "assets/img/list_good.png" //
: "assets/img/list_good_un.png" //
),
),
),
const Text("点赞"),
],
),
Column(
children: [
IconButton(
onPressed: () {
Navigator.pop(context);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CommentView(
id: songs[index].id,
song: songs[index].title,
singer: songs[index].artist,
cover: songs[index].artistPic,
),
),
);
},
icon: Image.asset("assets/img/list_comment.png"),
iconSize: 60,
),
const Text("评论")
],
),
],
),
],
),
);
},
),
);
}
}

@ -0,0 +1,409 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:music_player_miao/api/api_music_likes_list.dart';
import 'package:music_player_miao/common_widget/app_data.dart';
import 'package:music_player_miao/models/getLikeList_bean.dart';
import 'package:music_player_miao/view_model/home_view_model.dart';
import '../music_view.dart';
import '../../common_widget/Song_widegt.dart';
import '../../common/download_manager.dart';
///
class MyLikesView extends StatefulWidget {
const MyLikesView({Key? key}) : super(key: key);
@override
State<MyLikesView> createState() => _MyLikesViewState();
}
class _MyLikesViewState extends State<MyLikesView> {
//
List<LikeListData> likedSongs = [];
//
bool _isSelectMode = false;
//
List<bool> _selectedItems = [];
//
final listVM = Get.put(HomeViewModel());
final downloadManager = Get.put(DownloadManager());
@override
void initState() {
super.initState();
//
_fetchLikedSongs();
}
///
Future<void> _fetchLikedSongs() async {
try {
// API
LikeListBean response = await LikesListApi().getUserLikesList(
Authorization: AppData().currentToken,
);
//
if (response.code == 200 && response.data != null) {
setState(() {
likedSongs = response.data!;
//
_selectedItems = List.generate(likedSongs.length, (index) => false);
});
}
} catch (error) {
print('Error fetching liked songs: $error');
}
}
@override
Widget build(BuildContext context) {
return Container(
//
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/img/app_bg.png"),
fit: BoxFit.cover,
),
),
child: Scaffold(
backgroundColor: Colors.transparent,
//
appBar: AppBar(
backgroundColor: Colors.transparent,
centerTitle: true,
elevation: 0,
//
leading: !_isSelectMode
? IconButton( //
onPressed: () {
Get.back(result: true);
},
icon: Image.asset(
"assets/img/back.png",
width: 25,
height: 25,
fit: BoxFit.contain,
),
)
: TextButton( //
onPressed: () {
setState(() {
_selectedItems = List.generate(likedSongs.length, (index) => true);
});
},
style: TextButton.styleFrom(
foregroundColor: Colors.black,
minimumSize: const Size(50, 40),
padding: const EdgeInsets.symmetric(horizontal: 8),
),
child: const Text(
'全选',
style: TextStyle(fontSize: 18),
),
),
//
title: _isSelectMode
? Text(
'已选中 ${_selectedItems.where((item) => item).length} 首歌曲',
style: const TextStyle(
color: Colors.black,
),
)
: const Text(
'我的点赞',
style: TextStyle(color: Colors.black),
),
//
actions: [
if (_isSelectMode)
TextButton(
onPressed: () {
setState(() {
_isSelectMode = false;
_selectedItems = List.generate(likedSongs.length, (index) => false);
});
},
child: const Text(
"完成",
style: TextStyle(color: Colors.black, fontSize: 18),
))
],
),
//
body: Container(
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.vertical(top: Radius.circular(30)),
),
child: Column(
children: [
//
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
//
Row(
children: [
IconButton(
onPressed: likedSongs.isEmpty
? null
: () {
// TODO:
},
icon: Image.asset(
"assets/img/button_play.png",
width: 20,
height: 20,
),
),
const Text(
'播放全部',
style: TextStyle(fontSize: 16),
),
const SizedBox(width: 5),
Text(
'(${likedSongs.length})',
style: const TextStyle(fontSize: 16),
),
],
),
//
IconButton(
onPressed: likedSongs.isEmpty ? null : () {
setState(() {
_isSelectMode = !_isSelectMode;
if (!_isSelectMode) {
_selectedItems = List.generate(likedSongs.length, (index) => false);
}
});
},
icon: Image.asset(
"assets/img/list_op.png",
width: 20,
height: 20,
),
),
],
),
),
//
Expanded(
child: ListView.builder(
itemCount: likedSongs.length,
padding: EdgeInsets.zero,
itemBuilder: (context, index) {
final song = likedSongs[index];
return ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 16.0),
//
onTap: _isSelectMode
? () {
setState(() {
_selectedItems[index] = !_selectedItems[index];
});
}
: () async {
// Song
List<Song> songList = likedSongs.map((song) => Song(
id: song.id ?? 0,
title: song.name ?? '未知歌曲',
artist: song.singerName ?? '未知歌手',
artistPic: song.coverPath ?? '',
pic: song.coverPath ?? '',
musicurl: song.musicPath ?? '',
likes: song.likes,
collection: song.collection,
)).toList();
//
final result = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MusicView(
songList: songList,
initialSongIndex: index,
//
onSongStatusChanged: (index, isCollected, isLiked) {
setState(() {
songList[index].collection = isCollected;
songList[index].likes = isLiked;
downloadManager.updateSongInfo(
songList[index].id,
isCollected,
isLiked,
);
});
},
),
),
);
//
if (result != null) {
_fetchLikedSongs();
}
},
//
title: Row(
children: [
//
if (_isSelectMode)
Checkbox(
value: _selectedItems[index],
onChanged: (value) {
setState(() {
_selectedItems[index] = value!;
});
},
shape: const CircleBorder(),
activeColor: const Color(0xff429482),
),
//
ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Image.network(
song.coverPath ?? '',
width: 60,
height: 60,
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) {
return Image.asset(
"assets/img/artist_pic.png",
width: 60,
height: 60,
);
},
),
),
const SizedBox(width: 12),
//
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
song.name ?? '未知歌曲',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 16,
color: Colors.black,
),
),
Text(
song.singerName ?? '未知歌手',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 14,
color: Colors.black54,
),
),
],
),
),
],
),
);
},
),
),
],
),
),
//
bottomNavigationBar: _isSelectMode
? BottomAppBar(
height: 140,
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
//
Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
// "添加到"
Expanded(
child: InkWell(
onTap: () {
// TODO:
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: 25,
height: 25,
child: Image.asset("assets/img/add.png"),
),
const SizedBox(width: 4),
const Text("添加到"),
],
),
),
),
// 线
Container(
height: 50,
width: 2,
color: const Color(0xff429482),
),
// "删除"
Expanded(
child: InkWell(
onTap: () {
// TODO:
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: 22,
height: 22,
child: Image.asset("assets/img/delete.png"),
),
const SizedBox(width: 4),
const Text("删除"),
],
),
),
),
],
),
),
//
ElevatedButton(
onPressed: () {
setState(() {
_isSelectMode = false;
_selectedItems = List.generate(likedSongs.length, (index) => false);
});
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xff429482),
padding: const EdgeInsets.symmetric(vertical: 14),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
),
),
child: const Text(
'取消',
style: TextStyle(color: Colors.black, fontSize: 16),
),
),
],
),
),
)
: null,
),
);
}
}

@ -19,6 +19,9 @@ import '../../common/download_manager.dart';
import '../../common/password_manager.dart';
import '../../models/search_bean.dart';
import 'my_work_view.dart';
import 'my_likes_view.dart';
import 'package:music_player_miao/api/api_music_likes_list.dart'; // API
import 'package:music_player_miao/models/getLikeList_bean.dart'; //
class UserView extends StatefulWidget {
const UserView({super.key});
@ -37,6 +40,8 @@ class UserViewState extends State<UserView> with AutomaticKeepAliveClientMixin {
String avatar = AppData().currentAvatar;
String username = AppData().currentUsername;
final audioController = Get.find<AudioPlayerController>();
int likesCount = 0;
final downloadManager = Get.put(DownloadManager());
final downloadCountController = Get.put(DownloadCountController());
@ -48,6 +53,8 @@ class UserViewState extends State<UserView> with AutomaticKeepAliveClientMixin {
super.initState();
_fetchSonglistData();
downloadCountController.refreshCount(downloadManager);
downloadCount = downloadManager.completedNumber();
_fetchLikesCount();
}
Future<void> _fetchSonglistData() async {
@ -66,6 +73,22 @@ class UserViewState extends State<UserView> with AutomaticKeepAliveClientMixin {
}
}
Future<void> _fetchLikesCount() async {
try {
LikeListBean response = await LikesListApi().getUserLikesList(
Authorization: AppData().currentToken,
);
if (response.code == 200 && response.data != null) {
setState(() {
likesCount = response.data!.length;
});
}
} catch (error) {
print('Error fetching likes count: $error');
}
}
@override
Widget build(BuildContext context) {
super.build(context);
@ -129,10 +152,50 @@ class UserViewState extends State<UserView> with AutomaticKeepAliveClientMixin {
padding: const EdgeInsets.only(
left: 15, right: 15, top: 20, bottom: 20),
//
//
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
//
InkWell(
onTap: () async {
final result = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const MyLikesView(),
),
);
if (result == true) {
_fetchLikesCount();
}
},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Image.asset("assets/img/artist_pic.png"),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"我的点赞",
style: TextStyle(fontSize: 20),
),
Text(
"$likesCount",
style: const TextStyle(fontSize: 16),
),
],
),
const SizedBox(width: 80),
Image.asset("assets/img/user_next.png")
],
),
),
const SizedBox(height: 10),
//
InkWell(
onTap: () {
Navigator.push(
@ -178,9 +241,9 @@ class UserViewState extends State<UserView> with AutomaticKeepAliveClientMixin {
onTap: () async {
final result = await Navigator.push(
context,
MaterialPageRoute(
MaterialPageRoute(
builder: (context) => const MyDownloadView(),
),
),
);
if (result == true) {

Loading…
Cancel
Save