Skip to content

Commit

Permalink
🎨 utils-EventBus添加null-safe (LianjiaTech#23)
Browse files Browse the repository at this point in the history
* 🎨 utils-EventBus添加null-safe

* 🎨 修改theme配置功能及utils/brn_tools工具函数 null-safe

* 🎨 EventBus添加null-safe(其他提交请忽略,输入回退)

Co-authored-by: 大脸儿 <[email protected]>
  • Loading branch information
2 people authored and leftcoding committed Dec 31, 2021
1 parent 09ca6d7 commit c0ff1cb
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/src/utils/brn_event_bus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class EventBus {
/// listener is affected. A paused listener will buffer events internally until
/// resumed or cancelled. So it's usually better to just cancel and later
/// subscribe again (avoids memory leak).
Stream<T> on<T>() {
///
Stream on<T>() {
if (T == dynamic) {
return streamController.stream as Stream<T>;
}
Expand All @@ -79,4 +80,19 @@ class EventBus {
void destroy() {
_streamController.close();
}
static EventBus? _instance;

factory EventBus.init() {
if (_instance == null) {
_instance = EventBus();
}
return _instance!;
}

static EventBus get instance {
if (_instance == null) {
EventBus.init();
}
return _instance!;
}
}

0 comments on commit c0ff1cb

Please sign in to comment.