|
|
|
@ -3,21 +3,23 @@ import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
import 'package:just_audio/just_audio.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 '../api/api_music_likes.dart';
|
|
|
|
|
import '../api/api_collection.dart';
|
|
|
|
|
import '../common/download_manager.dart';
|
|
|
|
|
import '../common_widget/Song_widegt.dart';
|
|
|
|
|
import '../models/universal_bean.dart';
|
|
|
|
|
|
|
|
|
|
class MusicView extends StatefulWidget {
|
|
|
|
|
final List<Song> songList;
|
|
|
|
|
final int initialSongIndex;
|
|
|
|
|
final Function(int index, bool isCollected, bool isLiked)? onSongStatusChanged;
|
|
|
|
|
|
|
|
|
|
const MusicView({
|
|
|
|
|
super.key,
|
|
|
|
|
required this.songList,
|
|
|
|
|
required this.initialSongIndex
|
|
|
|
|
required this.initialSongIndex,
|
|
|
|
|
this.onSongStatusChanged,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@ -379,14 +381,23 @@ class _MusicViewState extends State<MusicView> {
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
IconButton(
|
|
|
|
|
// TODO 该处存在 BUG,影响功能:点赞
|
|
|
|
|
// 原因:同收藏功能
|
|
|
|
|
onPressed: () async{
|
|
|
|
|
setState(() {
|
|
|
|
|
likesnot = !likesnot;
|
|
|
|
|
likes[currentSongIndex] = !likes[currentSongIndex];
|
|
|
|
|
});
|
|
|
|
|
await LikesApiMusic().likesMusic(musicId: id[currentSongIndex], Authorization: AppData().currentToken);
|
|
|
|
|
|
|
|
|
|
UniversalBean response = await LikesApiMusic().likesMusic(musicId: id[currentSongIndex], Authorization: AppData().currentToken);
|
|
|
|
|
if (response.code != 200) {
|
|
|
|
|
likesnot = !likesnot;
|
|
|
|
|
likes[currentSongIndex] = !likes[currentSongIndex];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
widget.onSongStatusChanged?.call(
|
|
|
|
|
currentSongIndex,
|
|
|
|
|
collection[currentSongIndex], // 传递当前的收藏状态
|
|
|
|
|
likes[currentSongIndex]
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
icon: Image.asset(
|
|
|
|
|
likesnot
|
|
|
|
@ -397,17 +408,23 @@ class _MusicViewState extends State<MusicView> {
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
IconButton(
|
|
|
|
|
// TODO 该处存在 BUG,影响功能:收藏
|
|
|
|
|
// 原因:这个视图接收的数据从父组件传递过来
|
|
|
|
|
// 在这更新数据不会影响父组件的数据,所以在父组件中的数据不会改变
|
|
|
|
|
// 所以从父组件进入该组件,显示的点赞和收藏数据均是父组件初始化的时候从服务器获取的,而不是最新的
|
|
|
|
|
// 同理,点赞逻辑也存在这个 BUG
|
|
|
|
|
onPressed: () async{
|
|
|
|
|
setState(() {
|
|
|
|
|
collectionsnot = !collectionsnot;
|
|
|
|
|
collection[currentSongIndex] = !collection[currentSongIndex];
|
|
|
|
|
});
|
|
|
|
|
await CollectionApiMusic().addCollection(musicId: id[currentSongIndex], Authorization: AppData().currentToken);
|
|
|
|
|
|
|
|
|
|
UniversalBean response = await CollectionApiMusic().addCollection(musicId: id[currentSongIndex], Authorization: AppData().currentToken);
|
|
|
|
|
if (response.code != 200) {
|
|
|
|
|
collectionsnot = !collectionsnot;
|
|
|
|
|
collection[currentSongIndex] = !collection[currentSongIndex];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
widget.onSongStatusChanged?.call(
|
|
|
|
|
currentSongIndex,
|
|
|
|
|
collection[currentSongIndex],
|
|
|
|
|
likes[currentSongIndex] // 传递当前的点赞状态
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
icon: Image.asset(
|
|
|
|
|
collectionsnot
|
|
|
|
|