diff --git a/lib/main.dart b/lib/main.dart index 55e3880..9891502 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -7,6 +7,7 @@ import 'package:permission_handler/permission_handler.dart'; import 'package:flutter/services.dart'; import 'services/audio_service.dart'; +import 'services/route_manager.dart'; import 'services/playback_service.dart'; import 'services/app_lifecycle_service.dart'; import 'services/webdav_service.dart'; @@ -107,28 +108,6 @@ void main() async { }); } -// ════════════════════════════════════════════════════════════ -// 路由管理器(控制 MiniPlayer 显示/隐藏) -// ════════════════════════════════════════════════════════════ -class RouteManager extends ChangeNotifier { - static final RouteManager _instance = RouteManager._internal(); - factory RouteManager() => _instance; - RouteManager._internal(); - - String _currentRoute = '/'; - String get currentRoute => _currentRoute; - - bool get showMiniPlayer => - _currentRoute != '/player' && _currentRoute != '/playlist'; - - void updateRoute(String route) { - if (_currentRoute != route) { - _currentRoute = route; - debugPrint('📌 路由更新: $route'); - notifyListeners(); - } - } -} // ════════════════════════════════════════════════════════════ // 导航观察者(监听路由变化) @@ -399,8 +378,7 @@ class _QTPlayerAppState extends State { animation: RouteManager(), builder: (context, _) { final routeManager = RouteManager(); - final shouldShow = routeManager.currentRoute != '/player' && - routeManager.currentRoute != '/playlist'; + final shouldShow = routeManager.showMiniPlayer; return AnimatedSwitcher( duration: const Duration(milliseconds: 300), @@ -436,4 +414,4 @@ class _QTPlayerAppState extends State { ), ); } -} +} \ No newline at end of file diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index 386387b..c6a00c4 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -436,9 +436,18 @@ class _HomePageState extends BaseState { delegate: SliverChildBuilderDelegate( (context, index) { final song = _favorites[index]; - return AnimatedOpacity( - opacity: 1.0, - duration: const Duration(milliseconds: 150), + return TweenAnimationBuilder( + key: ValueKey('fav-$_homeTab-$index'), + tween: Tween(begin: 0.0, end: 1.0), + duration: const Duration(milliseconds: 240), + curve: Curves.easeOutCubic, + builder: (context, t, child) => Opacity( + opacity: t, + child: Transform.translate( + offset: Offset(0, (1 - t) * 10), + child: child, + ), + ), child: Padding( padding: const EdgeInsets.symmetric(vertical: 2), child: ListTile( @@ -515,8 +524,20 @@ class _HomePageState extends BaseState { delegate: SliverChildBuilderDelegate( (context, index) { final playlist = _playlistSummaries[index]; - return Padding( - padding: const EdgeInsets.symmetric(vertical: 2), + return TweenAnimationBuilder( + key: ValueKey('pl-$_homeTab-$index'), + tween: Tween(begin: 0.0, end: 1.0), + duration: const Duration(milliseconds: 240), + curve: Curves.easeOutCubic, + builder: (context, t, child) => Opacity( + opacity: t, + child: Transform.translate( + offset: Offset(0, (1 - t) * 10), + child: child, + ), + ), + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 2), child: ListTile( contentPadding: EdgeInsets.zero, visualDensity: VisualDensity.compact, @@ -561,7 +582,8 @@ class _HomePageState extends BaseState { if (mounted) safeSetState(() {}); }, ), - ); + ), + ); }, childCount: _playlistSummaries.length, ), diff --git a/lib/services/route_manager.dart b/lib/services/route_manager.dart new file mode 100644 index 0000000..9eba161 --- /dev/null +++ b/lib/services/route_manager.dart @@ -0,0 +1,34 @@ +// lib/services/route_manager.dart +import 'package:flutter/foundation.dart'; + +/// 路由管理器(控制 MiniPlayer 显示/隐藏) +class RouteManager extends ChangeNotifier { + static final RouteManager _instance = RouteManager._internal(); + factory RouteManager() => _instance; + RouteManager._internal(); + + String _currentRoute = '/'; + String get currentRoute => _currentRoute; + + /// 弹层/对话框打开时临时隐藏迷你播放器,避免盖住内容 + bool _temporarilyHidden = false; + + bool get showMiniPlayer => + !_temporarilyHidden && + _currentRoute != '/player' && + _currentRoute != '/playlist'; + + void setTemporarilyHidden(bool hidden) { + if (_temporarilyHidden == hidden) return; + _temporarilyHidden = hidden; + notifyListeners(); + } + + void updateRoute(String route) { + if (_currentRoute != route) { + _currentRoute = route; + debugPrint('📌 路由更新: $route'); + notifyListeners(); + } + } +} diff --git a/lib/widgets/add_to_playlist_sheet.dart b/lib/widgets/add_to_playlist_sheet.dart index 7df2fa0..6860fcd 100644 --- a/lib/widgets/add_to_playlist_sheet.dart +++ b/lib/widgets/add_to_playlist_sheet.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import '../models/playlist_summary.dart'; import '../repositories/playlist_repository.dart'; +import '../services/route_manager.dart'; /// 把一首歌加入歌单的底部弹层。 /// @@ -26,11 +27,14 @@ Future showAddToPlaylistSheet( } if (!context.mounted) return; + RouteManager().setTemporarilyHidden(true); + try { await showModalBottomSheet( context: context, backgroundColor: const Color(0xFF1A1F1E), builder: (sheetContext) { return SafeArea( + minimum: const EdgeInsets.only(bottom: 12), child: Column( mainAxisSize: MainAxisSize.min, children: [ @@ -109,12 +113,15 @@ Future showAddToPlaylistSheet( }, ), ), - const SizedBox(height: 8), + const SizedBox(height: 16), ], ), ); }, ); + } finally { + RouteManager().setTemporarilyHidden(false); + } } Future _createPlaylistAndAdd( @@ -163,4 +170,4 @@ Future _createPlaylistAndAdd( SnackBar(content: Text('新建歌单失败: $e')), ); } -} +} \ No newline at end of file