Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 utils-EventBus添加null-safe #23

Merged
merged 5 commits into from
Dec 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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!;
}
}