fix(favorite): 收藏状态变化时主页实时刷新
之前主页收藏列表只在启动或从文件列表返回时重查, 在播放页/文件列表点红心,主页不会变。 - 新增 FavoriteEvents(songPath 事件) - 文件列表、播放页收藏/取消后 publish - 主页订阅后重新拉取收藏列表
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user