// lib/widgets/global_mini_player.dart import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../services/audio_service.dart'; import '../main.dart'; class GlobalMiniPlayer extends StatelessWidget { const GlobalMiniPlayer({super.key}); // ✅ 全局回调:打开播放页 static VoidCallback? onOpenPlayerPage; // ✅ 新增:打开播放列表 static VoidCallback? onOpenPlaylistPage; @override Widget build(BuildContext context) { final service = context.watch(); final song = service.currentSong; final bottomPadding = MediaQuery.of(context).padding.bottom; return GestureDetector( onTap: () { if (song != null && onOpenPlayerPage != null) { onOpenPlayerPage!(); } }, child: Container( height: 56 + bottomPadding, decoration: BoxDecoration( color: const Color(0xFF1A1F1E), boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.4), blurRadius: 12, offset: const Offset(0, -4), ), ], ), child: SafeArea( top: false, bottom: true, child: Padding( padding: const EdgeInsets.only(bottom: 0), child: Row( children: [ const SizedBox(width: 12), Container( width: 40, height: 40, decoration: BoxDecoration( color: song != null ? const Color(0xFF2A3332) : Colors.grey[800], borderRadius: BorderRadius.circular(4), ), child: Icon( song != null ? Icons.music_note : Icons.music_off, color: song != null ? Colors.white38 : Colors.grey[600], size: 20, ), ), const SizedBox(width: 12), Expanded( child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( song != null ? song.title : '清听', style: const TextStyle( fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white, decoration: TextDecoration.none, ), maxLines: 1, overflow: TextOverflow.ellipsis, ), Text( song != null ? song.artist : '未播放', style: TextStyle( fontSize: 12, color: song != null ? Colors.grey[400] : Colors.grey[600], decoration: TextDecoration.none, ), maxLines: 1, overflow: TextOverflow.ellipsis, ), ], ), ), IconButton( icon: Icon( song != null && service.isPlaying ? Icons.pause : Icons.play_arrow, color: song != null ? Colors.white : Colors.grey[600], size: 24, ), onPressed: () { if (song != null) { service.togglePlay(); } }, ), IconButton( icon: Icon( Icons.playlist_play_outlined, color: Colors.grey[500], size: 24, ), onPressed: () { // ✅ 使用回调打开播放列表(与播放页同一套层级) if (onOpenPlaylistPage != null) { onOpenPlaylistPage!(); } }, ), const SizedBox(width: 4), ], ), ), ), ), ); } }