You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
264 lines
9.0 KiB
264 lines
9.0 KiB
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
import '../../../routes/app_routes.dart';
|
|
import '../../../data/services/qq_musoc.dart';
|
|
import '../../../data/models/song_model.dart';
|
|
import 'circular_progress_button.dart';
|
|
|
|
/// 构建音乐项目
|
|
Widget buildQQMusicItem(
|
|
BuildContext context, String id, String name, String singer, String image) {
|
|
final qqMusicService = QqMusocService.to; // 使用QQ音乐全局服务
|
|
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
|
|
|
// 创建SongModel对象 - 修复字段名
|
|
final song = SongModel(
|
|
mid: id,
|
|
name: name,
|
|
artist: singer, // 修复:使用 artist 而不是 singer
|
|
album: '', // 添加必需的 album 字段
|
|
duration: 0, // 默认时长,实际播放时会更新
|
|
albumPic: image, // 修复:使用 albumPic 而不是 pic
|
|
);
|
|
|
|
return Container(
|
|
padding: EdgeInsets.all(14.w),
|
|
decoration: BoxDecoration(
|
|
color: isDarkMode ? const Color(0xFF1E1E1E) : Colors.white,
|
|
borderRadius: BorderRadius.circular(12.r),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withValues(alpha: isDarkMode ? 0.2 : 0.03),
|
|
blurRadius: 3,
|
|
spreadRadius: 1,
|
|
offset: const Offset(0, 1),
|
|
),
|
|
],
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
width: 50.w,
|
|
height: 50.h,
|
|
decoration: BoxDecoration(
|
|
color: isDarkMode ? Colors.grey[800] : Colors.grey[100],
|
|
borderRadius: BorderRadius.circular(8.r),
|
|
image: image.isNotEmpty
|
|
? DecorationImage(
|
|
image: NetworkImage(image),
|
|
fit: BoxFit.cover,
|
|
)
|
|
: null,
|
|
),
|
|
child: image.isEmpty
|
|
? Icon(
|
|
Icons.music_note,
|
|
size: 18.sp,
|
|
color: Theme.of(context).primaryColor,
|
|
)
|
|
: null,
|
|
),
|
|
SizedBox(width: 12.w),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
name,
|
|
style: TextStyle(
|
|
fontSize: 13.sp,
|
|
fontWeight: FontWeight.w500,
|
|
color: isDarkMode
|
|
? Colors.white.withValues(alpha: 0.9)
|
|
: Colors.grey[800],
|
|
),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
SizedBox(height: 2.h),
|
|
Text(
|
|
singer,
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
color: isDarkMode ? Colors.grey[400] : Colors.grey[600],
|
|
),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Obx(() {
|
|
// 使用QQ音乐服务的全局状态
|
|
final isThisPlaying = qqMusicService.isPlaying.value &&
|
|
qqMusicService.currentSong.value?.mid == id;
|
|
|
|
// 计算播放进度
|
|
final currentProgress =
|
|
isThisPlaying && qqMusicService.totalDuration.value > 0
|
|
? qqMusicService.currentPosition.value /
|
|
qqMusicService.totalDuration.value
|
|
: 0.0;
|
|
|
|
return CircularProgressButton(
|
|
isPlaying: isThisPlaying,
|
|
progress: currentProgress,
|
|
primaryColor: Theme.of(context).primaryColor,
|
|
backgroundColor: Colors.grey,
|
|
size: 36.0,
|
|
strokeWidth: 2.0,
|
|
onPlayPause: () async {
|
|
try {
|
|
if (qqMusicService.isPlaying.value) {
|
|
if (qqMusicService.currentSong.value?.mid == id) {
|
|
// 当前歌曲正在播放,暂停它
|
|
await qqMusicService.pauseMusic();
|
|
} else {
|
|
// 其他歌曲正在播放,播放这首歌
|
|
await qqMusicService.playSongs(
|
|
songMids: [id],
|
|
index: 0,
|
|
songList: [song],
|
|
currentSongModel: song,
|
|
);
|
|
}
|
|
} else {
|
|
if (qqMusicService.currentSong.value?.mid == id) {
|
|
// 当前歌曲已暂停,恢复播放
|
|
await qqMusicService.resumeMusic();
|
|
} else {
|
|
// 播放新歌曲
|
|
await qqMusicService.playSongs(
|
|
songMids: [id],
|
|
index: 0,
|
|
songList: [song],
|
|
currentSongModel: song,
|
|
);
|
|
}
|
|
}
|
|
} catch (e) {
|
|
// 静默处理错误,避免影响用户体验
|
|
print('播放控制失败: $e');
|
|
}
|
|
},
|
|
onSeek: isThisPlaying
|
|
? (seekProgress) {
|
|
// QQ音乐暂不支持拖拽进度,可以在这里添加相关逻辑
|
|
// 或者显示提示信息
|
|
print('QQ音乐暂不支持拖拽进度');
|
|
}
|
|
: null,
|
|
);
|
|
}),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 构建音乐内容卡片
|
|
Widget buildQQMusicContent(
|
|
BuildContext context, List<Map<String, dynamic>> playlist) {
|
|
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
|
final qqMusicService = QqMusocService.to; // 使用QQ音乐全局服务
|
|
|
|
// 将播放列表转换为SongModel列表 - 修复字段名
|
|
final songList = playlist
|
|
.map((item) => SongModel(
|
|
mid: item["mid"] ?? "",
|
|
name: item["name"] ?? "未知歌曲",
|
|
artist: item["singer"] ?? "未知歌手", // 修复:使用 artist 而不是 singer
|
|
album: '', // 添加必需的 album 字段
|
|
duration: 0,
|
|
albumPic: item["pic"] ?? "", // 修复:使用 albumPic 而不是 pic
|
|
))
|
|
.toList();
|
|
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'recommendedMusic'.tr, //以下是一些推荐的音乐:
|
|
style: TextStyle(
|
|
color:
|
|
isDarkMode ? Colors.white.withValues(alpha: 0.9) : Colors.black87,
|
|
fontSize: 14,
|
|
height: 1.4,
|
|
fontWeight: FontWeight.w400,
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Icon(
|
|
Icons.music_note,
|
|
size: 16,
|
|
// ignore: deprecated_member_use
|
|
color: Theme.of(context).primaryColor.withOpacity(0.7),
|
|
),
|
|
const SizedBox(width: 6),
|
|
Text(
|
|
'playList'.tr, //播放列表
|
|
style: TextStyle(
|
|
fontSize: 13,
|
|
fontWeight: FontWeight.w600,
|
|
color: Theme.of(context).brightness == Brightness.dark
|
|
? Colors.grey[300]
|
|
: Colors.grey[700],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 10),
|
|
|
|
// 动态生成音乐条目
|
|
...playlist.asMap().entries.take(4).map((entry) {
|
|
final index = entry.key;
|
|
final item = entry.value;
|
|
final mid = item["mid"];
|
|
final name = item["name"] ?? "未知歌曲";
|
|
final singer = item["singer"] ?? "未知歌手";
|
|
final image = item["pic"] ?? "";
|
|
return Column(
|
|
children: [
|
|
buildQQMusicItem(context, mid, name, singer, image),
|
|
if (index != playlist.length - 1)
|
|
Divider(
|
|
height: 1,
|
|
thickness: 1,
|
|
color: Theme.of(context).brightness == Brightness.dark
|
|
? Colors.grey[800]
|
|
: Colors.grey[100],
|
|
),
|
|
],
|
|
);
|
|
}).toList(),
|
|
const SizedBox(height: 8),
|
|
Center(
|
|
child: TextButton(
|
|
onPressed: () {
|
|
// 跳转到完整歌单页面,传递完整的歌单数据
|
|
Get.toNamed(Routes.qqmusic, arguments: {"playlist": playlist});
|
|
},
|
|
style: TextButton.styleFrom(
|
|
minimumSize: Size.zero,
|
|
padding:
|
|
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
|
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
),
|
|
child: Text(
|
|
'moreMusic'.tr, //更多音乐,
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
color: Theme.of(context).primaryColor,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|