From c854ab290bfd164ed9faea0be13fa6ecd5881125 Mon Sep 17 00:00:00 2001 From: Sandy <15143015732@163.com> Date: Fri, 31 Dec 2021 22:49:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20EventBus=20=20=E5=8D=95?= =?UTF-8?q?=E4=BE=8B=E5=AE=9E=E7=8E=B0=20(#43)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Theme: 优化单例实现,初步优化 BrnAllThemeConfig 属性获取不为 null * refactor:优化theme,暴露非null引用 * theme:去除无用信息及优化部分代码 * theme:增加属性类型 * 优化修复 EventBus --- lib/src/utils/brn_event_bus.dart | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/lib/src/utils/brn_event_bus.dart b/lib/src/utils/brn_event_bus.dart index f9c96247..9d3832a6 100644 --- a/lib/src/utils/brn_event_bus.dart +++ b/lib/src/utils/brn_event_bus.dart @@ -32,16 +32,15 @@ class EventBus { static EventBus? _instance; - factory EventBus.init() { - _instance = EventBus(); + factory EventBus._() { + if(_instance == null) { + _instance = EventBus(); + } return _instance!; } static EventBus get instance { - if (_instance == null) { - EventBus.init(); - } - return _instance!; + return EventBus._(); } StreamController _streamController; @@ -64,7 +63,7 @@ class EventBus { /// resumed or cancelled. So it's usually better to just cancel and later /// subscribe again (avoids memory leak). /// - Stream on() { + Stream on() { if (T == dynamic) { return streamController.stream as Stream; } @@ -80,19 +79,5 @@ 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!; - } }