fix(favorite): 收藏状态变化时主页实时刷新
之前主页收藏列表只在启动或从文件列表返回时重查, 在播放页/文件列表点红心,主页不会变。 - 新增 FavoriteEvents(songPath 事件) - 文件列表、播放页收藏/取消后 publish - 主页订阅后重新拉取收藏列表
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
// lib/services/favorite_events.dart
|
||||
import 'dart:async';
|
||||
|
||||
/// 收藏状态变化事件。
|
||||
///
|
||||
/// 文件列表、播放页都能收藏/取消收藏,主页的收藏列表需要跟着变,
|
||||
/// 否则要退出重进才看得到。
|
||||
class FavoriteEvents {
|
||||
static final FavoriteEvents _instance = FavoriteEvents._internal();
|
||||
factory FavoriteEvents() => _instance;
|
||||
FavoriteEvents._internal();
|
||||
|
||||
final StreamController<String> _controller =
|
||||
StreamController<String>.broadcast();
|
||||
|
||||
Stream<String> get stream => _controller.stream;
|
||||
|
||||
void publish(String songPath) {
|
||||
if (songPath.isEmpty) return;
|
||||
_controller.add(songPath);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user