部分界面逻辑调整:播放界面默认最高优先级,其次是独立的miniplayerbar
This commit is contained in:
@@ -2,13 +2,15 @@
|
||||
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});
|
||||
|
||||
// ✅ 通过全局回调打开播放页(由 main.dart 注入)
|
||||
static VoidCallback? onOpenPlayerPage;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final service = context.watch<AudioService>();
|
||||
@@ -18,13 +20,8 @@ class GlobalMiniPlayer extends StatelessWidget {
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
if (song != null) {
|
||||
// ✅ 使用 navigatorKey 跳转
|
||||
navigatorKey.currentState?.push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => const PlayerPage(),
|
||||
),
|
||||
);
|
||||
if (song != null && onOpenPlayerPage != null) {
|
||||
onOpenPlayerPage!();
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
@@ -115,7 +112,6 @@ class GlobalMiniPlayer extends StatelessWidget {
|
||||
size: 24,
|
||||
),
|
||||
onPressed: () {
|
||||
// ✅ 使用 navigatorKey 跳转
|
||||
navigatorKey.currentState?.push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => const PlaylistPage(),
|
||||
|
||||
@@ -1,117 +0,0 @@
|
||||
// lib/widgets/mini_player_bar.dart
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../services/audio_service.dart';
|
||||
import '../pages/player_page.dart';
|
||||
|
||||
class MiniPlayerBar extends StatelessWidget {
|
||||
const MiniPlayerBar({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final service = context.watch<AudioService>();
|
||||
final song = service.currentSong;
|
||||
|
||||
if (song == null) return const SizedBox.shrink();
|
||||
|
||||
return SafeArea(
|
||||
top: false,
|
||||
bottom: true,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => const PlayerPage(),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
height: 64,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF1A1F1E),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.4),
|
||||
blurRadius: 12,
|
||||
offset: const Offset(0, -4),
|
||||
),
|
||||
],
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Colors.transparent,
|
||||
Colors.black.withOpacity(0.1),
|
||||
],
|
||||
stops: const [0.0, 1.0],
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 12),
|
||||
Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF2A3332),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.music_note,
|
||||
color: Colors.white38,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
song.title,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.white,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Text(
|
||||
song.artist,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
service.isPlaying ? Icons.pause : Icons.play_arrow,
|
||||
color: Colors.white,
|
||||
),
|
||||
onPressed: () {
|
||||
service.togglePlay();
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.playlist_play_outlined,
|
||||
color: Colors.white54,
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user