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 1 commit
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
12 changes: 4 additions & 8 deletions lib/src/utils/brn_event_bus.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @dart=2.9

import 'dart:async';

/// Dispatches events to listeners using the Dart [Stream] API. The [EventBus]
Expand All @@ -15,6 +13,7 @@ import 'dart:async';
/// github: https://github.com/marcojakob/dart-event-bus
///
class EventBus {
late bool sync;
StreamController _streamController;

/// Controller for the event bus stream.
Expand All @@ -26,7 +25,7 @@ class EventBus {
/// during a [fire] call. If false (the default), the event will be passed to
/// the listeners at a later time, after the code creating the event has
/// completed.
EventBus({bool sync = false})
EventBus({sync = false})
: _streamController = StreamController.broadcast(sync: sync);

/// Instead of using the default [StreamController] you can use this constructor
Expand All @@ -51,7 +50,7 @@ class EventBus {
/// unpaused or canceled. 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;
} else {
Expand All @@ -71,17 +70,14 @@ class EventBus {
_streamController.close();
}

static EventBus _instance;
static EventBus _instance = new EventBus.init();

factory EventBus.init() {
_instance = EventBus();
kkkman22 marked this conversation as resolved.
Show resolved Hide resolved
return _instance;
}

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