自习室优化ok

This commit is contained in:
zhutao
2025-11-28 18:01:09 +08:00
parent 57305c5804
commit 54bf2dcee7
38 changed files with 527 additions and 117 deletions

33
lib/global/event_bus.dart Normal file
View File

@@ -0,0 +1,33 @@
import 'dart:async';
/// 全局事件总线
class EventBus {
EventBus._();
static final _instance = EventBus._();
factory EventBus() => _instance;
// StreamController广播模式可以让多个地方监听
final StreamController<GlobalEvent> _controller = StreamController.broadcast();
/// 发送事件
void fire(GlobalEvent event) {
_controller.add(event);
}
/// 监听事件
Stream<GlobalEvent> get stream => _controller.stream;
/// 关闭流(一般应用生命周期结束时调用)
void dispose() {
_controller.close();
}
}
/// 事件类型枚举
enum GlobalEvent {
unauthorized, // 401 需要重新登录
// 以后可以扩展其他事件
}