// lib/pages/playlist_page.dart import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../services/audio_service.dart'; class PlaylistPage extends StatelessWidget { const PlaylistPage({super.key}); @override Widget build(BuildContext context) { final service = context.watch(); final queue = service.queue; final currentIndex = service.currentIndex; return Scaffold( backgroundColor: const Color(0xFF0E1211), appBar: AppBar( title: const Text( '播放列表', style: TextStyle( color: Colors.white, fontSize: 18, fontWeight: FontWeight.w500, ), ), backgroundColor: Colors.transparent, elevation: 0, foregroundColor: Colors.white, leading: IconButton( icon: const Icon(Icons.arrow_back_ios_new), onPressed: () => Navigator.pop(context), ), actions: [ IconButton( icon: const Icon(Icons.clear_all, color: Colors.white54), onPressed: () { showDialog( context: context, builder: (context) => AlertDialog( backgroundColor: const Color(0xFF1A1F1E), title: const Text( '清空播放列表', style: TextStyle(color: Colors.white), ), content: const Text( '确定要清空当前播放列表吗?', style: TextStyle(color: Colors.grey), ), actions: [ TextButton( onPressed: () => Navigator.pop(context), child: const Text('取消'), ), TextButton( onPressed: () { service.clearQueue(); Navigator.pop(context); Navigator.pop(context); }, child: const Text( '清空', style: TextStyle(color: Colors.red), ), ), ], ), ); }, ), ], ), body: queue.isEmpty ? const Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon(Icons.playlist_play, size: 48, color: Colors.grey), SizedBox(height: 16), Text( '播放列表为空', style: TextStyle(color: Colors.grey), ), ], ), ) : ListView.builder( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), itemCount: queue.length, itemBuilder: (context, index) { final song = queue[index]; final isCurrent = index == currentIndex; return ListTile( contentPadding: const EdgeInsets.symmetric( horizontal: 8, vertical: 4, ), leading: Icon( isCurrent ? Icons.play_arrow : Icons.music_note, color: isCurrent ? const Color(0xFFB8D4D0) : Colors.grey[600], size: 24, ), title: Text( song.title, style: TextStyle( fontSize: 16, fontWeight: isCurrent ? FontWeight.w600 : FontWeight.w400, color: isCurrent ? Colors.white : Colors.grey[300], ), maxLines: 1, overflow: TextOverflow.ellipsis, ), subtitle: Text( song.artist, style: TextStyle( fontSize: 13, color: isCurrent ? Colors.grey[400] : Colors.grey[600], ), maxLines: 1, overflow: TextOverflow.ellipsis, ), trailing: isCurrent ? Container( padding: const EdgeInsets.symmetric( horizontal: 8, vertical: 2, ), decoration: BoxDecoration( color: const Color(0xFFB8D4D0).withOpacity(0.2), borderRadius: BorderRadius.circular(4), ), child: const Text( '正在播放', style: TextStyle( fontSize: 10, color: Color(0xFFB8D4D0), ), ), ) : null, onTap: () { service.setQueue(queue, startIndex: index); Navigator.pop(context); }, ); }, ), ); } }