部分界面逻辑调整:播放界面默认最高优先级,其次是独立的miniplayerbar

This commit is contained in:
2026-08-18 23:08:52 +08:00
parent c05398d76f
commit 74a15ca7af
5 changed files with 103 additions and 164 deletions
+59 -35
View File
@@ -2,16 +2,23 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../services/audio_service.dart';
import '../main.dart'; // ✅ 导入 navigatorKey
import 'playlist_page.dart'; // ✅ 导入 PlaylistPage
class PlayerPage extends StatefulWidget {
const PlayerPage({super.key});
final VoidCallback onClose;
const PlayerPage({
super.key,
required this.onClose,
});
@override
State<PlayerPage> createState() => _PlayerPageState();
}
class _PlayerPageState extends State<PlayerPage> {
double? _dragProgress; // 拖动时的临时进度
double? _dragProgress;
String _formatDuration(Duration d) {
if (d.inMilliseconds < 0) return '00:00';
@@ -28,10 +35,24 @@ class _PlayerPageState extends State<PlayerPage> {
if (song == null) {
return Scaffold(
backgroundColor: const Color(0xFF0E1211),
body: const Center(
child: Text(
'没有正在播放的歌曲',
style: TextStyle(color: Colors.grey),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'没有正在播放的歌曲',
style: TextStyle(color: Colors.grey),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: widget.onClose,
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFFB8D4D0),
foregroundColor: Colors.black87,
),
child: const Text('返回'),
),
],
),
),
);
@@ -51,7 +72,6 @@ class _PlayerPageState extends State<PlayerPage> {
.clamp(0.0, 1.0)
: 0.0;
// 拖动时显示拖动的进度,否则显示实际播放进度
final displayProgress = _dragProgress ?? progress;
return Scaffold(
@@ -61,7 +81,7 @@ class _PlayerPageState extends State<PlayerPage> {
elevation: 0,
leading: IconButton(
icon: const Icon(Icons.arrow_back_ios_new, color: Colors.white),
onPressed: () => Navigator.pop(context),
onPressed: widget.onClose, // ✅ 使用回调关闭
),
title: const Text(
'正在播放',
@@ -73,6 +93,17 @@ class _PlayerPageState extends State<PlayerPage> {
),
centerTitle: true,
actions: [
IconButton(
icon:
const Icon(Icons.playlist_play_outlined, color: Colors.white54),
onPressed: () {
navigatorKey.currentState?.push(
MaterialPageRoute(
builder: (_) => const PlaylistPage(),
),
);
},
),
IconButton(
icon: const Icon(Icons.more_vert, color: Colors.white54),
onPressed: () {},
@@ -84,7 +115,6 @@ class _PlayerPageState extends State<PlayerPage> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// ---- 封面占位 ----
Container(
width: 240,
height: 240,
@@ -106,8 +136,6 @@ class _PlayerPageState extends State<PlayerPage> {
),
),
const SizedBox(height: 48),
// ---- 歌曲信息 ----
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
@@ -136,8 +164,6 @@ class _PlayerPageState extends State<PlayerPage> {
],
),
const SizedBox(height: 40),
// ---- 双层进度条(视觉与交互分离) ----
Column(
children: [
SizedBox(
@@ -145,15 +171,14 @@ class _PlayerPageState extends State<PlayerPage> {
child: LayoutBuilder(
builder: (context, constraints) {
final width = constraints.maxWidth;
final bufferWidth =
width * bufferProgress.clamp(0.0, 1.0);
final progressWidth = width * progress.clamp(0.0, 1.0);
final progressWidth =
width * displayProgress.clamp(0.0, 1.0);
return Stack(
alignment: Alignment.centerLeft,
children: [
// ① 底层:整首歌曲(暗灰色)
Container(
width: width,
height: 4,
@@ -162,8 +187,6 @@ class _PlayerPageState extends State<PlayerPage> {
borderRadius: BorderRadius.circular(2),
),
),
// ② 缓冲层(深青色)
Container(
width: bufferWidth,
height: 4,
@@ -172,8 +195,6 @@ class _PlayerPageState extends State<PlayerPage> {
borderRadius: BorderRadius.circular(2),
),
),
// ③ 播放进度层(亮青色)
Container(
width: progressWidth,
height: 4,
@@ -182,26 +203,23 @@ class _PlayerPageState extends State<PlayerPage> {
borderRadius: BorderRadius.circular(2),
),
),
// ④ 交互层(只负责手势,不显示任何轨道)
Positioned.fill(
child: SliderTheme(
data: SliderTheme.of(context).copyWith(
trackHeight: 0,
activeTrackColor: Colors.transparent,
inactiveTrackColor: Colors.transparent,
thumbColor: Colors.transparent, // ✅ 完全隐藏小球
thumbColor: Colors.transparent,
overlayColor: Colors.transparent,
thumbShape: const RoundSliderThumbShape(
enabledThumbRadius: 0,
),
),
child: Slider(
value: progress.clamp(0.0, 1.0),
value: displayProgress.clamp(0.0, 1.0),
min: 0.0,
max: 1.0,
onChanged: (value) {
// 拖动时只更新本地状态,不触发 seek
setState(() {
_dragProgress = value;
});
@@ -225,7 +243,6 @@ class _PlayerPageState extends State<PlayerPage> {
},
),
),
// 时间显示
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
@@ -248,15 +265,23 @@ class _PlayerPageState extends State<PlayerPage> {
],
),
const SizedBox(height: 32),
// ---- 播放控制 ----
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(
onPressed: () {},
onPressed: service.togglePlayMode,
icon: Icon(
service.playModeIcon,
color: const Color(0xFFB8D4D0),
size: 22,
),
padding: const EdgeInsets.all(12),
),
const SizedBox(width: 4),
IconButton(
onPressed: service.hasQueue ? service.previous : null,
icon: const Icon(Icons.skip_previous, size: 28),
color: Colors.white60,
color: service.hasQueue ? Colors.white60 : Colors.grey[600],
padding: const EdgeInsets.all(12),
),
const SizedBox(width: 20),
@@ -274,18 +299,17 @@ class _PlayerPageState extends State<PlayerPage> {
size: 28,
),
padding: EdgeInsets.zero,
onPressed: () {
service.togglePlay();
},
onPressed: service.togglePlay,
),
),
const SizedBox(width: 20),
IconButton(
onPressed: () {},
onPressed: service.hasQueue ? service.next : null,
icon: const Icon(Icons.skip_next, size: 28),
color: Colors.white60,
color: service.hasQueue ? Colors.white60 : Colors.grey[600],
padding: const EdgeInsets.all(12),
),
const SizedBox(width: 4),
],
),
const SizedBox(height: 16),