页面层级与返回逻辑实现完成,并且去掉web相关代码支持
This commit is contained in:
+117
-102
@@ -1,128 +1,143 @@
|
||||
// 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<AudioService>();
|
||||
final song = service.currentSong;
|
||||
final audioService = context.watch<AudioService>();
|
||||
final song = audioService.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),
|
||||
),
|
||||
],
|
||||
return Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
// 底层遮罩
|
||||
Positioned(
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
child: Container(
|
||||
height: 56 + bottomPadding,
|
||||
color: const Color(0xFF1A1F1E),
|
||||
),
|
||||
),
|
||||
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,
|
||||
// 上层主体
|
||||
Positioned(
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: bottomPadding,
|
||||
child: ClipRRect(
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
bottom: Radius.circular(16),
|
||||
),
|
||||
child: Container(
|
||||
height: 56,
|
||||
color: const Color(0xFF1A1F1E),
|
||||
// ⭐ 用 Material 包裹 InkWell,获得更好的点击反馈
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
if (song != null) {
|
||||
navigatorKey.currentState?.pushNamed('/player');
|
||||
}
|
||||
},
|
||||
// ⭐ 让整个区域都响应点击,包括空白部分
|
||||
highlightColor: Colors.white.withOpacity(0.05),
|
||||
splashColor: Colors.white.withOpacity(0.1),
|
||||
child: Row(
|
||||
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,
|
||||
const SizedBox(width: 12),
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: song != null
|
||||
? Colors.grey[400]
|
||||
: Colors.grey[600],
|
||||
decoration: TextDecoration.none,
|
||||
? 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,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
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 && audioService.isPlaying
|
||||
? Icons.pause
|
||||
: Icons.play_arrow,
|
||||
color: song != null ? Colors.white : Colors.grey[600],
|
||||
size: 24,
|
||||
),
|
||||
onPressed: () {
|
||||
if (song != null) {
|
||||
audioService.togglePlay();
|
||||
}
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.playlist_play_outlined,
|
||||
color: Colors.grey,
|
||||
size: 24,
|
||||
),
|
||||
onPressed: () {
|
||||
if (song != null) {
|
||||
navigatorKey.currentState?.pushNamed('/playlist');
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
),
|
||||
),
|
||||
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: () {
|
||||
// ✅ 使用静态回调,而不是 Navigator.pushNamed
|
||||
if (onOpenPlaylistPage != null) {
|
||||
onOpenPlaylistPage!();
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user