部分界面调整,把底部的播放控件完整前置

This commit is contained in:
2026-08-18 22:57:29 +08:00
parent e96da3fb04
commit c05398d76f
7 changed files with 708 additions and 48 deletions
+134
View File
@@ -0,0 +1,134 @@
// lib/widgets/global_mini_player.dart
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../services/audio_service.dart';
import '../pages/player_page.dart';
import '../pages/playlist_page.dart';
import '../main.dart'; // ✅ 导入 navigatorKey
class GlobalMiniPlayer extends StatelessWidget {
const GlobalMiniPlayer({super.key});
@override
Widget build(BuildContext context) {
final service = context.watch<AudioService>();
final song = service.currentSong;
final bottomPadding = MediaQuery.of(context).padding.bottom;
return GestureDetector(
onTap: () {
if (song != null) {
// ✅ 使用 navigatorKey 跳转
navigatorKey.currentState?.push(
MaterialPageRoute(
builder: (_) => const PlayerPage(),
),
);
}
},
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: () {
// ✅ 使用 navigatorKey 跳转
navigatorKey.currentState?.push(
MaterialPageRoute(
builder: (_) => const PlaylistPage(),
),
);
},
),
const SizedBox(width: 4),
],
),
),
),
),
);
}
}