fix(favorite): 收藏状态变化时主页实时刷新

之前主页收藏列表只在启动或从文件列表返回时重查,
在播放页/文件列表点红心,主页不会变。

- 新增 FavoriteEvents(songPath 事件)
- 文件列表、播放页收藏/取消后 publish
- 主页订阅后重新拉取收藏列表
This commit is contained in:
2026-11-01 15:24:28 +08:00
parent b6e2340aae
commit a927e3dd44
4 changed files with 36 additions and 0 deletions
+2
View File
@@ -5,6 +5,7 @@ import 'package:provider/provider.dart';
import '../base/base_state.dart';
import '../database/song_database.dart';
import '../services/audio_service.dart';
import '../services/favorite_events.dart';
class PlayerPage extends StatefulWidget {
final VoidCallback? onClose;
@@ -138,6 +139,7 @@ class _PlayerPageState extends BaseState<PlayerPage> {
Future<void> _toggleFavorite(Song song) async {
try {
await SongDatabase().toggleFavorite(song.id);
FavoriteEvents().publish(song.id);
final favorite = await SongDatabase().isFavorite(song.id);
if (!mounted) return;
setState(() => _isFavorite = favorite);