feat: 调整侧边按钮为点赞

master
Spark 4 days ago
parent 04e09c2507
commit afd2adff5a

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

@ -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<MusicsListBean> 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<MusicListBean> 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<MusicListBean> getMusic2({required String Authorization}) async {
Response response = await dio.get(
_getMusic2,

@ -0,0 +1,35 @@
class MusicsListBean {
int? code;
String? msg;
List<MusicItem>? 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'];
}
}

@ -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<HomeView>
Future<void> _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<HomeView>
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<HomeView>
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: () {},
);
}),
),
],
),
),

@ -273,20 +273,21 @@ class _RankViewState extends State<RankView> 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)

Loading…
Cancel
Save