@ -0,0 +1,2 @@
|
||||
#Mon Oct 28 21:45:22 CST 2024
|
||||
java.home=C\:\\Program Files\\Android\\Android Studio\\jbr
|
||||
@ -0,0 +1,8 @@
|
||||
## This file must *NOT* be checked into Version Control Systems,
|
||||
# as it contains information specific to your local configuration.
|
||||
#
|
||||
# Location of the SDK. This is only used by Gradle.
|
||||
# For customization when using a Version Control System, please read the
|
||||
# header note.
|
||||
#Mon Oct 28 21:45:22 CST 2024
|
||||
sdk.dir=C\:\\Users\\zxp\\AppData\\Local\\Android\\Sdk
|
||||
@ -1,3 +1,4 @@
|
||||
org.gradle.jvmargs=-Xmx1536M
|
||||
android.useAndroidX=true
|
||||
android.enableJetifier=true
|
||||
systemProp.org.gradle.wrapper.timeout=300000
|
||||
|
||||
|
After Width: | Height: | Size: 749 B |
|
After Width: | Height: | Size: 356 B |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 299 KiB |
|
After Width: | Height: | Size: 589 B |
@ -0,0 +1,3 @@
|
||||
description: This file stores settings for Dart & Flutter DevTools.
|
||||
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
|
||||
extensions:
|
||||
@ -0,0 +1,30 @@
|
||||
// api/api_collection.dart
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:music_player_miao/models/universal_bean.dart';
|
||||
|
||||
const String _CollectionURL = 'http://8.210.250.29:10010/collections';
|
||||
|
||||
class CollectionApiMusic {
|
||||
final Dio dio = Dio();
|
||||
|
||||
/// 添加收藏
|
||||
Future<UniversalBean> addCollection({
|
||||
required int musicId,
|
||||
required String Authorization,
|
||||
}) async {
|
||||
|
||||
Response response = await dio.post(
|
||||
_CollectionURL,
|
||||
queryParameters: {'musicId': musicId},
|
||||
options: Options(headers: {
|
||||
'Authorization': Authorization,
|
||||
'Content-Type': 'application/json;charset=UTF-8'
|
||||
})
|
||||
);
|
||||
|
||||
print(response.data);
|
||||
return UniversalBean.formMap(response.data); // 将返回的数据转换为 UniversalBean 对象
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,201 @@
|
||||
// audio_player_controller.dart
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:just_audio/just_audio.dart';
|
||||
import '../common_widget/Song_widegt.dart';
|
||||
import '../models/getMusicList_bean.dart';
|
||||
import '../common/download_manager.dart';
|
||||
import '../common_widget/app_data.dart';
|
||||
import '../api/api_music_list.dart';
|
||||
|
||||
class AudioPlayerController extends GetxController {
|
||||
final audioPlayer = AudioPlayer();
|
||||
final downloadManager = Get.find<DownloadManager>();
|
||||
final appData = AppData();
|
||||
|
||||
// Observable values
|
||||
final currentSongIndex = 0.obs;
|
||||
final duration = Duration.zero.obs;
|
||||
final position = Duration.zero.obs;
|
||||
final isPlaying = false.obs;
|
||||
final isLoading = false.obs;
|
||||
final isRotating = false.obs;
|
||||
final isDisposed = false.obs;
|
||||
|
||||
// Current song info
|
||||
final artistName = ''.obs;
|
||||
final musicName = ''.obs;
|
||||
final likesStatus = false.obs;
|
||||
final collectionsStatus = false.obs;
|
||||
|
||||
// Song lists
|
||||
final songList = <Song>[].obs;
|
||||
final ids = <int>[].obs;
|
||||
final songUrls = <String>[].obs;
|
||||
final artists = <String>[].obs;
|
||||
final musicNames = <String>[].obs;
|
||||
final likes = <bool>[].obs;
|
||||
final collections = <bool>[].obs;
|
||||
|
||||
StreamSubscription? _positionSubscription;
|
||||
StreamSubscription? _durationSubscription;
|
||||
StreamSubscription? _playerStateSubscription;
|
||||
|
||||
void initWithSongs(List<Song> songs, int initialIndex) {
|
||||
songList.value = songs;
|
||||
currentSongIndex.value = initialIndex;
|
||||
_initializeSongLists();
|
||||
_initializePlayer();
|
||||
}
|
||||
|
||||
void _initializeSongLists() {
|
||||
for (int i = 0; i < songList.length; i++) {
|
||||
ids.add(songList[i].id);
|
||||
songUrls.add(songList[i].musicurl ?? '');
|
||||
artists.add(songList[i].artist);
|
||||
musicNames.add(songList[i].title);
|
||||
likes.add(songList[i].likes ?? false);
|
||||
collections.add(songList[i].collection ?? false);
|
||||
}
|
||||
_updateCurrentSongInfo();
|
||||
}
|
||||
|
||||
void _initializePlayer() {
|
||||
// Position updates
|
||||
_positionSubscription = audioPlayer.positionStream.listen((pos) {
|
||||
position.value = pos;
|
||||
});
|
||||
|
||||
// Duration updates
|
||||
_durationSubscription = audioPlayer.durationStream.listen((dur) {
|
||||
duration.value = dur ?? Duration.zero;
|
||||
});
|
||||
|
||||
// Player state updates
|
||||
_playerStateSubscription = audioPlayer.playerStateStream.listen((state) {
|
||||
// isPlaying.value = state.playing;
|
||||
if (state.processingState == ProcessingState.completed) {
|
||||
playNext();
|
||||
}
|
||||
});
|
||||
|
||||
// Initial load
|
||||
_loadAndPlayCurrentSong();
|
||||
}
|
||||
|
||||
void _updateCurrentSongInfo() {
|
||||
artistName.value = artists[currentSongIndex.value];
|
||||
musicName.value = musicNames[currentSongIndex.value];
|
||||
likesStatus.value = likes[currentSongIndex.value];
|
||||
collectionsStatus.value = collections[currentSongIndex.value];
|
||||
}
|
||||
|
||||
Future<void> toggleLike() async {
|
||||
final currentIndex = currentSongIndex.value;
|
||||
likesStatus.value = !likesStatus.value;
|
||||
likes[currentIndex] = likesStatus.value;
|
||||
}
|
||||
|
||||
Future<void> toggleCollection() async {
|
||||
final currentIndex = currentSongIndex.value;
|
||||
collectionsStatus.value = !collectionsStatus.value;
|
||||
collections[currentIndex] = collectionsStatus.value;
|
||||
}
|
||||
|
||||
Future<void> _loadAndPlayCurrentSong() async {
|
||||
isLoading.value = true;
|
||||
position.value = Duration.zero;
|
||||
duration.value = Duration.zero;
|
||||
_updateCurrentSongInfo();
|
||||
|
||||
await _checkAndUpdateSongStatus(currentSongIndex.value);
|
||||
|
||||
try {
|
||||
await audioPlayer.stop();
|
||||
|
||||
final localSong = downloadManager.getLocalSong(currentSongIndex.value);
|
||||
final audioSource = localSong != null
|
||||
? AudioSource.file(localSong.musicurl!)
|
||||
: AudioSource.uri(Uri.parse(songUrls[currentSongIndex.value]));
|
||||
|
||||
await audioPlayer.setAudioSource(audioSource, preload: true);
|
||||
duration.value = await audioPlayer.duration ?? Duration.zero;
|
||||
await audioPlayer.play();
|
||||
} catch (e) {
|
||||
print('Error loading audio source: $e');
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _checkAndUpdateSongStatus(int index) async {
|
||||
if (songList[index].likes == null || songList[index].collection == null) {
|
||||
try {
|
||||
MusicListBean musicListBean = await GetMusic().getMusicById(
|
||||
id: ids[index],
|
||||
Authorization: appData.currentToken,
|
||||
);
|
||||
|
||||
if (musicListBean.code == 200) {
|
||||
likes[index] = musicListBean.likeOrNot!;
|
||||
collections[index] = musicListBean.collectOrNot!;
|
||||
|
||||
if (index == currentSongIndex.value) {
|
||||
likesStatus.value = musicListBean.likeOrNot!;
|
||||
collectionsStatus.value = musicListBean.collectOrNot!;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error fetching song status: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void playOrPause() async {
|
||||
if (audioPlayer.playing) {
|
||||
isPlaying.value = false;
|
||||
await audioPlayer.pause();
|
||||
} else {
|
||||
await audioPlayer.play();
|
||||
isPlaying.value = true;
|
||||
}
|
||||
}
|
||||
|
||||
void playNext() {
|
||||
if (currentSongIndex.value < songList.length - 1) {
|
||||
currentSongIndex.value++;
|
||||
} else {
|
||||
currentSongIndex.value = 0;
|
||||
}
|
||||
_loadAndPlayCurrentSong();
|
||||
}
|
||||
|
||||
void playPrevious() {
|
||||
if (currentSongIndex.value > 0) {
|
||||
currentSongIndex.value--;
|
||||
} else {
|
||||
currentSongIndex.value = songList.length - 1;
|
||||
}
|
||||
_loadAndPlayCurrentSong();
|
||||
}
|
||||
|
||||
void seekTo(Duration position) async {
|
||||
await audioPlayer.seek(position);
|
||||
}
|
||||
|
||||
void changeSong(int index) {
|
||||
currentSongIndex.value = index;
|
||||
_loadAndPlayCurrentSong();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
isDisposed.value = true;
|
||||
_positionSubscription?.cancel();
|
||||
_durationSubscription?.cancel();
|
||||
_playerStateSubscription?.cancel();
|
||||
audioPlayer.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,213 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../api/api_download.dart';
|
||||
import '../common_widget/Song_widegt.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
class DownloadItem {
|
||||
final Song song;
|
||||
double progress;
|
||||
bool isCompleted;
|
||||
bool isDownloading;
|
||||
|
||||
DownloadItem({
|
||||
required this.song,
|
||||
this.progress = 0.0,
|
||||
this.isCompleted = false,
|
||||
this.isDownloading = false,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'song': {
|
||||
'pic': song.pic,
|
||||
'artistPic': song.artistPic,
|
||||
'title': song.title,
|
||||
'artist': song.artist,
|
||||
'musicurl': song.musicurl,
|
||||
'id': song.id,
|
||||
'likes': song.likes,
|
||||
'collection': song.collection
|
||||
},
|
||||
'progress': progress,
|
||||
'isCompleted': isCompleted,
|
||||
'isDownloading': isDownloading,
|
||||
};
|
||||
}
|
||||
|
||||
// 从JSON创建DownloadItem
|
||||
factory DownloadItem.fromJson(Map<String, dynamic> json) {
|
||||
return DownloadItem(
|
||||
song: Song(
|
||||
pic: json['song']['pic'],
|
||||
artistPic: json['song']['artistPic'],
|
||||
title: json['song']['title'],
|
||||
artist: json['song']['artist'],
|
||||
musicurl: json['song']['musicurl'],
|
||||
id: json['song']['id'],
|
||||
likes: json['song']['likes'],
|
||||
collection: json['song']['collection'],
|
||||
),
|
||||
progress: json['progress'],
|
||||
isCompleted: json['isCompleted'],
|
||||
isDownloading: json['isDownloading'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DownloadManager extends GetxController {
|
||||
static const String PREFS_KEY = 'downloads_data';
|
||||
final _downloads = <String, DownloadItem>{}.obs;
|
||||
final downloadApi = DownloadApi();
|
||||
late SharedPreferences _prefs;
|
||||
|
||||
@override
|
||||
void onInit() async {
|
||||
super.onInit();
|
||||
await _initPrefs();
|
||||
}
|
||||
|
||||
Future<void> _initPrefs() async {
|
||||
_prefs = await SharedPreferences.getInstance();
|
||||
await _loadDownloadsFromPrefs();
|
||||
}
|
||||
|
||||
// 从SharedPreferences加载数据
|
||||
Future<void> _loadDownloadsFromPrefs() async {
|
||||
final String? downloadsJson = _prefs.getString(PREFS_KEY);
|
||||
if (downloadsJson != null) {
|
||||
final Map<String, dynamic> downloadsMap = json.decode(downloadsJson);
|
||||
downloadsMap.forEach((key, value) {
|
||||
_downloads[key] = DownloadItem.fromJson(value);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 保存数据到SharedPreferences
|
||||
Future<void> _saveDownloadsToPrefs() async {
|
||||
final Map<String, dynamic> downloadsMap = {};
|
||||
_downloads.forEach((key, value) {
|
||||
downloadsMap[key] = value.toJson();
|
||||
});
|
||||
await _prefs.setString(PREFS_KEY, json.encode(downloadsMap));
|
||||
}
|
||||
|
||||
List<Song> getLocalSongs() {
|
||||
final localSongs = <Song>[];
|
||||
_downloads.forEach((key, value) {
|
||||
if (value.isCompleted) {
|
||||
localSongs.add(value.song);
|
||||
}
|
||||
});
|
||||
return localSongs;
|
||||
}
|
||||
|
||||
Map<String, DownloadItem> get downloads => _downloads;
|
||||
|
||||
bool isDownloading(int id) => _downloads[id.toString()]?.isDownloading ?? false;
|
||||
bool isCompleted(int id) => _downloads[id.toString()]?.isCompleted ?? false;
|
||||
double getProgress(int id) => _downloads[id.toString()]?.progress ?? 0.0;
|
||||
|
||||
Song? getLocalSong(int id) {
|
||||
final downloadItem = _downloads[id.toString()];
|
||||
if (downloadItem?.isCompleted ?? false) {
|
||||
return downloadItem!.song;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
bool removeSong(int id) {
|
||||
if (_downloads[id.toString()]?.isCompleted ?? false) {
|
||||
File file = File.fromUri(Uri.parse(_downloads[id.toString()]!.song.musicurl!));
|
||||
file.deleteSync();
|
||||
_downloads.remove(id.toString());
|
||||
_saveDownloadsToPrefs();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int completedNumber() {
|
||||
int count = 0;
|
||||
_downloads.forEach((key, value) {
|
||||
if (value.isCompleted) {
|
||||
count++;
|
||||
}
|
||||
});
|
||||
return count;
|
||||
}
|
||||
|
||||
Future<void> startDownload({
|
||||
required Song song,
|
||||
required context,
|
||||
}) async {
|
||||
if (_downloads[song.id.toString()]?.isDownloading ?? false) return;
|
||||
|
||||
final fileName = '${song.id}_${song.title}_${song.artist}';
|
||||
|
||||
final downloadItem = DownloadItem(
|
||||
song: song,
|
||||
isDownloading: true,
|
||||
);
|
||||
_downloads[song.id.toString()] = downloadItem;
|
||||
|
||||
try {
|
||||
final filePath = await downloadApi.downloadMusic(
|
||||
musicUrl: song.musicurl!,
|
||||
name: fileName,
|
||||
context: context,
|
||||
onProgress: (progress) {
|
||||
downloadItem.progress = progress;
|
||||
_downloads[song.id.toString()] = downloadItem;
|
||||
},
|
||||
);
|
||||
|
||||
if (filePath != null) {
|
||||
downloadItem.isCompleted = true;
|
||||
downloadItem.isDownloading = false;
|
||||
downloadItem.progress = 1.0;
|
||||
song.musicurl = _getLocalAudioPath(fileName, song.musicurl!);
|
||||
print(song.musicurl);
|
||||
} else {
|
||||
downloadItem.isDownloading = false;
|
||||
downloadItem.progress = 0.0;
|
||||
}
|
||||
} catch (e) {
|
||||
print('Download error: $e');
|
||||
downloadItem.isDownloading = false;
|
||||
downloadItem.progress = 0.0;
|
||||
}
|
||||
|
||||
_downloads[song.id.toString()] = downloadItem;
|
||||
await _saveDownloadsToPrefs();
|
||||
}
|
||||
|
||||
bool updateSongInfo(int id, bool isCollected, bool isLiked) {
|
||||
final downloadItem = _downloads[id.toString()];
|
||||
if (downloadItem != null) {
|
||||
downloadItem.song.collection = isCollected;
|
||||
downloadItem.song.likes = isLiked;
|
||||
_downloads[id.toString()] = downloadItem;
|
||||
_saveDownloadsToPrefs();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
String _getFileExtension(String url) {
|
||||
// Remove query parameters
|
||||
final urlWithoutQuery = url.split('?').first;
|
||||
// Get the extension including the dot
|
||||
final extension = path.extension(urlWithoutQuery);
|
||||
return extension.isNotEmpty ? extension : '.mp3'; // Default to .mp3 if no extension found
|
||||
}
|
||||
|
||||
String _getLocalAudioPath(String fileName, String url) {
|
||||
final extension = _getFileExtension(url);
|
||||
final fullFileName = '$fileName$extension';
|
||||
return path.join('/storage/emulated/0/MTMusic', fullFileName);
|
||||
}
|
||||
}
|
||||
@ -1,211 +1,260 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../api/api_music_likes.dart'; // 导入点赞 API
|
||||
import '../api/api_collection.dart'; // 导入收藏 API
|
||||
import '../view_model/comment_page.dart'; // 导入评论页面
|
||||
|
||||
class RankSongsRow extends StatelessWidget {
|
||||
final Map sObj;
|
||||
final VoidCallback onPressedPlay;
|
||||
final VoidCallback onPressed;
|
||||
final String? rank;
|
||||
|
||||
const RankSongsRow({
|
||||
super.key,
|
||||
required this.sObj,
|
||||
required this.onPressed,
|
||||
required this.onPressedPlay, required this.rank,
|
||||
required this.onPressedPlay,
|
||||
required this.rank,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
rank: sObj["rank"];
|
||||
return
|
||||
Column(
|
||||
children: [
|
||||
Row(
|
||||
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 15,
|
||||
child: RichText(
|
||||
text: TextSpan(
|
||||
text: sObj["rank"],
|
||||
style: TextStyle(
|
||||
fontSize: getRankFontSize(sObj["rank"]),
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Color(0xffCE0000),
|
||||
),
|
||||
return Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 15,
|
||||
child: RichText(
|
||||
text: TextSpan(
|
||||
text: sObj["rank"],
|
||||
style: TextStyle(
|
||||
fontSize: getRankFontSize(sObj["rank"]),
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Color(0xffCE0000),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10,),
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: Image.asset(
|
||||
sObj["image"],
|
||||
width: 80,
|
||||
height: 80,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: Image.asset(
|
||||
sObj["image"],
|
||||
width: 80,
|
||||
height: 80,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
|
||||
const SizedBox(width: 20,),
|
||||
SizedBox(
|
||||
width: 170,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
sObj["name"],
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w400),
|
||||
),
|
||||
Text(
|
||||
sObj["artists"],
|
||||
maxLines: 1,
|
||||
style: TextStyle(color: Colors.black, fontSize: 14),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
SizedBox(
|
||||
width: 170,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
sObj["name"],
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
sObj["artists"],
|
||||
maxLines: 1,
|
||||
style: TextStyle(color: Colors.black, fontSize: 14),
|
||||
)
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 20,),
|
||||
|
||||
|
||||
],
|
||||
),
|
||||
IconButton(
|
||||
onPressed: (){
|
||||
_bottomSheet(context);
|
||||
},
|
||||
icon: Image.asset(
|
||||
"assets/img/More.png",
|
||||
width: 25,
|
||||
height: 25,
|
||||
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
],
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
_bottomSheet(context);
|
||||
},
|
||||
icon: Image.asset(
|
||||
"assets/img/More.png",
|
||||
width: 25,
|
||||
height: 25,
|
||||
),
|
||||
const SizedBox(height: 20,)
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10,)
|
||||
],
|
||||
|
||||
);
|
||||
|
||||
),
|
||||
const SizedBox(height: 20)
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10)
|
||||
],
|
||||
);
|
||||
}
|
||||
getRankFontSize(String rank) {
|
||||
|
||||
double getRankFontSize(String rank) {
|
||||
switch (rank) {
|
||||
case '1': case '2':case '3':
|
||||
return 30.0;
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
return 30.0;
|
||||
default:
|
||||
return 20.0;
|
||||
}
|
||||
}
|
||||
Future _bottomSheet(BuildContext context){
|
||||
|
||||
Future _bottomSheet(BuildContext context) {
|
||||
return showModalBottomSheet(
|
||||
context: context,
|
||||
backgroundColor: Colors.white,
|
||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(30))),
|
||||
builder: (context) =>Container(
|
||||
height: 210,
|
||||
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,
|
||||
),
|
||||
Text("加入歌单")
|
||||
],
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: (){},
|
||||
icon: Image.asset("assets/img/list_download.png"),
|
||||
iconSize: 60,
|
||||
),
|
||||
Text("下载")
|
||||
],
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: (){},
|
||||
icon: Image.asset("assets/img/list_collection.png"),
|
||||
iconSize: 60,
|
||||
),
|
||||
Text("收藏")
|
||||
],
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: (){},
|
||||
icon: Image.asset("assets/img/list_good.png"),
|
||||
iconSize: 60,
|
||||
),
|
||||
Text("点赞")
|
||||
],
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: (){},
|
||||
icon: Image.asset("assets/img/list_comment.png"),
|
||||
iconSize: 60,
|
||||
),
|
||||
Text("评论")
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10,),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
// Get.to(()=>const MainTabView());
|
||||
},
|
||||
child: Text(
|
||||
"查看详情页",
|
||||
style: const TextStyle(color:Colors.black,fontSize: 18),
|
||||
context: context,
|
||||
backgroundColor: Colors.white,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(30))),
|
||||
builder: (context) => Container(
|
||||
height: 210,
|
||||
padding: const EdgeInsets.only(top: 20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
// TODO: 加入歌单的逻辑
|
||||
},
|
||||
icon: Image.asset("assets/img/list_add.png"),
|
||||
iconSize: 60,
|
||||
),
|
||||
Text("加入歌单"),
|
||||
],
|
||||
),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xffE6F4F1),
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.zero,
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
// TODO: 下载的逻辑
|
||||
},
|
||||
icon: Image.asset("assets/img/list_download.png"),
|
||||
iconSize: 60,
|
||||
),
|
||||
Text("下载"),
|
||||
],
|
||||
),
|
||||
|
||||
Column(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () async {
|
||||
// 点击收藏按钮时调用收藏 API
|
||||
await _toggleCollect();
|
||||
},
|
||||
icon: Image.asset("assets/img/list_collection.png"),
|
||||
iconSize: 60,
|
||||
),
|
||||
Text("收藏"),
|
||||
],
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () async {
|
||||
// 点击点赞按钮时调用点赞 API
|
||||
await _toggleLike();
|
||||
},
|
||||
icon: Image.asset("assets/img/list_good.png"),
|
||||
iconSize: 60,
|
||||
),
|
||||
Text("点赞"),
|
||||
],
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
// 跳转到评论页面
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const CommentPage(),
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: Image.asset("assets/img/list_comment.png"),
|
||||
iconSize: 60,
|
||||
),
|
||||
Text("评论"),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
// TODO: 查看详情页的逻辑
|
||||
},
|
||||
child: Text(
|
||||
"查看详情页",
|
||||
style: const TextStyle(color: Colors.black, fontSize: 18),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () =>Navigator.pop(context),
|
||||
child: Text(
|
||||
"取消",
|
||||
style: const TextStyle(color:Colors.black,fontSize: 18),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xffE6F4F1),
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.zero,
|
||||
),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xff429482),
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.zero,
|
||||
),
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(
|
||||
"取消",
|
||||
style: const TextStyle(color: Colors.black, fontSize: 18),
|
||||
),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xff429482),
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.zero,
|
||||
),
|
||||
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 点赞功能
|
||||
Future<void> _toggleLike() async {
|
||||
final api = LikesApiMusic(); // 实例化点赞 API
|
||||
try {
|
||||
String authorizationToken = 'eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI1ZDBmY2Q3ZThlYmY0N2QzOThlNmVjNDQ0ZTM5NTAxNSIsInN1YiI6IjEiLCJpc3MiOiJmbHlpbmdwaWciLCJpYXQiOjE3MzEwNDM3NTgsImV4cCI6MTczMzYzNTc1OH0.5jfhZtK46YNSC7KCaBWiPxSLO7Ym6ntBXnQwfsvMrCw'; // 替换为实际的授权 Token
|
||||
await api.likesMusic(
|
||||
musicId: sObj['id'], // 使用当前音乐的 ID
|
||||
Authorization: authorizationToken,
|
||||
);
|
||||
print('Liked music ID: ${sObj['id']}');
|
||||
} catch (e) {
|
||||
print('Error liking music: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 收藏功能
|
||||
Future<void> _toggleCollect() async {
|
||||
final api = CollectionApiMusic(); // 实例化收藏 API
|
||||
try {
|
||||
String authorizationToken = 'eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI1ZDBmY2Q3ZThlYmY0N2QzOThlNmVjNDQ0ZTM5NTAxNSIsInN1YiI6IjEiLCJpc3MiOiJmbHlpbmdwaWciLCJpYXQiOjE3MzEwNDM3NTgsImV4cCI6MTczMzYzNTc1OH0.5jfhZtK46YNSC7KCaBWiPxSLO7Ym6ntBXnQwfsvMrCw'; // 替换为实际的授权 Token
|
||||
await api.addCollection(
|
||||
musicId: sObj['id'], // 使用当前音乐的 ID
|
||||
Authorization: authorizationToken,
|
||||
);
|
||||
print('Collected music ID: ${sObj['id']}');
|
||||
} catch (e) {
|
||||
print('Error collecting music: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,43 @@
|
||||
class MyMusicListBean {
|
||||
int? code;
|
||||
String? msg;
|
||||
List<DataBean>? 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'];
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
class MyWorks {
|
||||
int? code;
|
||||
String? msg;
|
||||
List<DataBean>? data;
|
||||
|
||||
MyWorks.formMap(Map map) {
|
||||
code = map['code'];
|
||||
msg = map['msg'];
|
||||
if (map['data'] == null) return;
|
||||
|
||||
List<dynamic>? 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'];
|
||||
}
|
||||
}
|
||||
@ -1,304 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:music_player_miao/api/api_music_return.dart';
|
||||
import 'package:music_player_miao/common_widget/app_data.dart';
|
||||
import 'package:music_player_miao/models/getComment_bean.dart';
|
||||
import 'package:music_player_miao/models/universal_bean.dart';
|
||||
import 'package:music_player_miao/widget/text_field.dart';
|
||||
|
||||
|
||||
class CommentView extends StatefulWidget {
|
||||
@override
|
||||
_CommentViewState createState() => _CommentViewState();
|
||||
|
||||
CommentView({super.key, required this.initialSongIndex});
|
||||
|
||||
late final int initialSongIndex;
|
||||
}
|
||||
|
||||
class _CommentViewState extends State<CommentView> {
|
||||
List comments = [];
|
||||
|
||||
TextEditingController commentController = TextEditingController();
|
||||
FocusNode commentFocusNode = FocusNode();
|
||||
List commentTimes = [];
|
||||
List commentHeader = [];
|
||||
List commentName = [];
|
||||
bool ascendingOrder = true;
|
||||
int playlistCount = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_fetchSonglistData();
|
||||
}
|
||||
|
||||
Future<void> _fetchSonglistData() async {
|
||||
try {
|
||||
GetCommentBean bean1 = await getCommentApi().getComment(
|
||||
musicId: '1',
|
||||
pageNo: '0',
|
||||
pageSize: '10',
|
||||
Authorization: AppData().currentToken);
|
||||
setState(() {
|
||||
comments = bean1.rows!.map((rows) => rows.content!).toList();
|
||||
commentTimes = bean1.rows!.map((rows) => rows.time!).toList();
|
||||
commentHeader = bean1.rows!.map((rows) => rows.avatar!).toList();
|
||||
commentName = bean1.rows!.map((rows) => rows.username!).toList();
|
||||
playlistCount = comments.length;
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
if (error != null) {
|
||||
print('Response data: $error');
|
||||
} else {
|
||||
print('Error fetching songlist data: $error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
// backgroundColor: Colors.transparent,
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
backgroundColor: const Color(0xffF6FFD1),
|
||||
title: const Text(
|
||||
'评论(200)',
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 22
|
||||
),
|
||||
),
|
||||
elevation: 0,
|
||||
leading: IconButton(
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
},
|
||||
icon: Image.asset(
|
||||
"assets/img/back.png",
|
||||
width: 25,
|
||||
height: 25,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
Container(
|
||||
height: 80,
|
||||
padding: const EdgeInsets.only(left: 20, right: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xffF9F2AF),
|
||||
borderRadius: BorderRadius.circular(20)
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: Image.asset(
|
||||
"assets/img/artist_pic.png",
|
||||
width: 60,
|
||||
height: 60,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 20,),
|
||||
const Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
"背对背拥抱",
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w400),
|
||||
),
|
||||
Text(
|
||||
"林俊杰",
|
||||
maxLines: 1,
|
||||
style: TextStyle(color: Colors.black, fontSize: 14),
|
||||
)
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
icon: Image.asset(
|
||||
"assets/img/music_pause.png",
|
||||
width: 25,
|
||||
height: 25,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
"评论区",
|
||||
style: TextStyle(
|
||||
fontSize: 18
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
const Text(
|
||||
"时间",
|
||||
style: TextStyle(
|
||||
fontSize: 16
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
// setState(() {
|
||||
// ascendingOrder = !ascendingOrder;
|
||||
// comments.sort((a, b) {
|
||||
// int compare = ascendingOrder
|
||||
// ? commentTimes.indexOf(a).compareTo(
|
||||
// commentTimes.indexOf(b))
|
||||
// : commentTimes.indexOf(b).compareTo(
|
||||
// commentTimes.indexOf(a));
|
||||
// return compare;
|
||||
// });
|
||||
// });
|
||||
},
|
||||
icon: Image.asset(
|
||||
ascendingOrder
|
||||
? "assets/img/commend_up.png"
|
||||
: "assets/img/commend_down.png",
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
),
|
||||
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
/// 显示评论的区域
|
||||
Expanded(
|
||||
child:
|
||||
ListView.builder(
|
||||
itemCount: comments.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ListTile(
|
||||
title: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
backgroundImage: NetworkImage(commentHeader[index])
|
||||
),
|
||||
const SizedBox(width: 10,),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(commentName[index],
|
||||
style: const TextStyle(fontSize: 18)),
|
||||
const SizedBox(width: 8),
|
||||
// Adjust the spacing between elements
|
||||
Text(commentTimes[index],
|
||||
style: const TextStyle(fontSize: 14),),
|
||||
// Add the timestamp
|
||||
],
|
||||
),
|
||||
],
|
||||
), // Ad
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 50, top: 10, bottom: 20),
|
||||
child: Text(
|
||||
comments[index],
|
||||
style: const TextStyle(
|
||||
fontSize: 18), // Customize the font size if needed
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: 560,
|
||||
height: 2,
|
||||
color: const Color(0xffE3F0ED),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
///输入框和提交按钮
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextFieldColor(
|
||||
controller: commentController,
|
||||
hintText: '来发表你的评论吧!',
|
||||
)
|
||||
),
|
||||
const SizedBox(width: 8.0),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
submitComment();
|
||||
UniversalBean bean = await commentMusic().comment(
|
||||
musicId: widget.initialSongIndex,
|
||||
content: commentController.text,
|
||||
Authorization: AppData().currentToken);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xff429482),
|
||||
// Change Colors.blue to your desired background color
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(
|
||||
10), // Adjust the radius as needed
|
||||
),
|
||||
minimumSize: const Size(30, 44),
|
||||
),
|
||||
child: const Text(
|
||||
'提交',
|
||||
style: TextStyle(
|
||||
fontSize: 16
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void submitComment() {
|
||||
String comment = commentController.text;
|
||||
if (comment.isNotEmpty) {
|
||||
DateTime currentTime = DateTime.now();
|
||||
String formattedTime = "${currentTime.year}/${currentTime
|
||||
.month}/${currentTime.day} ${currentTime.hour}:${currentTime.minute}";
|
||||
|
||||
setState(() {
|
||||
comments.add(comment);
|
||||
commentTimes.add(formattedTime);
|
||||
commentName.add(AppData().currentUsername);
|
||||
commentHeader.add(AppData().currentAvatar);
|
||||
commentController.clear();
|
||||
playlistCount++;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class CommentPage extends StatefulWidget {
|
||||
const CommentPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_CommentPageState createState() => _CommentPageState();
|
||||
}
|
||||
|
||||
class _CommentPageState extends State<CommentPage> {
|
||||
final TextEditingController _controller = TextEditingController();
|
||||
final List<String> _comments = ["这是第一个评论", "很喜欢这首歌!"]; // 初始评论示例
|
||||
|
||||
void _addComment() {
|
||||
if (_controller.text.isNotEmpty) {
|
||||
setState(() {
|
||||
_comments.insert(0, _controller.text); // 插入到顶部
|
||||
});
|
||||
_controller.clear(); // 清空输入框
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('评论'),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
// 评论列表区域
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
reverse: true, // 新评论显示在顶部
|
||||
itemCount: _comments.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ListTile(
|
||||
leading: const CircleAvatar(
|
||||
child: Icon(Icons.person),
|
||||
),
|
||||
title: Text(_comments[index]),
|
||||
subtitle: Text('${DateTime.now().difference(DateTime.now().subtract(Duration(minutes: index * 5))).inMinutes} 分钟前'),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
// 评论输入区域
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _controller,
|
||||
decoration: InputDecoration(
|
||||
hintText: '输入你的评论...',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
),
|
||||
),
|
||||
onSubmitted: (_) => _addComment(), // 按回车提交评论
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.send, color: Colors.blue),
|
||||
onPressed: _addComment,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||