更新
This commit is contained in:
23
lib/common/util/EventBus.dart
Normal file
23
lib/common/util/EventBus.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
import 'dart:async';
|
||||
|
||||
class EventBus {
|
||||
static final EventBus _instance = EventBus._internal();
|
||||
factory EventBus() => _instance;
|
||||
EventBus._internal();
|
||||
|
||||
final _controller = StreamController.broadcast();
|
||||
|
||||
// 发出任意事件
|
||||
void emit(event) {
|
||||
_controller.add(event);
|
||||
}
|
||||
|
||||
// 监听指定类型的事件
|
||||
Stream<T> on<T>() {
|
||||
return _controller.stream.where((event) => event is T).cast<T>();
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
_controller.close();
|
||||
}
|
||||
}
|
||||
14
lib/common/util/eventType.dart
Normal file
14
lib/common/util/eventType.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
class VideoDownloadEvent {
|
||||
final bool success;
|
||||
VideoDownloadEvent(this.success);
|
||||
}
|
||||
|
||||
class BleConnectEvent {
|
||||
final bool connected;
|
||||
BleConnectEvent(this.connected);
|
||||
}
|
||||
|
||||
class SwitchLanguageEvent {
|
||||
final String language;
|
||||
SwitchLanguageEvent(this.language);
|
||||
}
|
||||
Reference in New Issue
Block a user