权限配置暂时到此,后台播放问题并入生命周期管理同步开发

This commit is contained in:
2026-08-20 22:07:59 +08:00
parent b2c7582ca7
commit f94cda4234
9 changed files with 787 additions and 364 deletions
+7 -10
View File
@@ -1,3 +1,4 @@
// lib/widgets/global_mini_player.dart
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../services/audio_service.dart';
@@ -8,15 +9,16 @@ class GlobalMiniPlayer extends StatelessWidget {
@override
Widget build(BuildContext context) {
final audioService = context.watch<AudioService>();
final song = audioService.currentSong;
// ⭐ 用 Selector 只监听 currentSong(低频变化)
final song = context.select<AudioService, Song?>((s) => s.currentSong);
// ⭐ 只监听播放状态(低频变化)
final isPlaying = context.select<AudioService, bool>((s) => s.isPlaying);
final bottomPadding = MediaQuery.of(context).padding.bottom;
return Stack(
clipBehavior: Clip.none,
children: [
// 底层遮罩
Positioned(
left: 0,
right: 0,
@@ -26,7 +28,6 @@ class GlobalMiniPlayer extends StatelessWidget {
color: const Color(0xFF1A1F1E),
),
),
// 上层主体
Positioned(
left: 0,
right: 0,
@@ -38,7 +39,6 @@ class GlobalMiniPlayer extends StatelessWidget {
child: Container(
height: 56,
color: const Color(0xFF1A1F1E),
// ⭐ 用 Material 包裹 InkWell,获得更好的点击反馈
child: Material(
color: Colors.transparent,
child: InkWell(
@@ -47,7 +47,6 @@ class GlobalMiniPlayer extends StatelessWidget {
navigatorKey.currentState?.pushNamed('/player');
}
},
// ⭐ 让整个区域都响应点击,包括空白部分
highlightColor: Colors.white.withOpacity(0.05),
splashColor: Colors.white.withOpacity(0.1),
child: Row(
@@ -81,7 +80,6 @@ class GlobalMiniPlayer extends StatelessWidget {
fontSize: 14,
fontWeight: FontWeight.w500,
color: Colors.white,
// ⭐ 强制去掉下划线
decoration: TextDecoration.none,
),
maxLines: 1,
@@ -94,7 +92,6 @@ class GlobalMiniPlayer extends StatelessWidget {
color: song != null
? Colors.grey[400]
: Colors.grey[600],
// ⭐ 强制去掉下划线
decoration: TextDecoration.none,
),
maxLines: 1,
@@ -105,7 +102,7 @@ class GlobalMiniPlayer extends StatelessWidget {
),
IconButton(
icon: Icon(
song != null && audioService.isPlaying
song != null && isPlaying
? Icons.pause
: Icons.play_arrow,
color: song != null ? Colors.white : Colors.grey[600],
@@ -113,7 +110,7 @@ class GlobalMiniPlayer extends StatelessWidget {
),
onPressed: () {
if (song != null) {
audioService.togglePlay();
context.read<AudioService>().togglePlay();
}
},
),