diff --git a/lib/pages/main/view.dart b/lib/pages/main/view.dart index 709fd073..429fdcc8 100644 --- a/lib/pages/main/view.dart +++ b/lib/pages/main/view.dart @@ -12,7 +12,6 @@ import 'package:PiliPlus/pages/home/view.dart'; import 'package:PiliPlus/pages/main/controller.dart'; import 'package:PiliPlus/pages/mine/controller.dart'; import 'package:PiliPlus/utils/app_scheme.dart'; -import 'package:PiliPlus/utils/event_bus.dart'; import 'package:PiliPlus/utils/extension.dart'; import 'package:PiliPlus/utils/feed_back.dart'; import 'package:PiliPlus/utils/storage.dart'; @@ -163,7 +162,6 @@ class _MainAppState extends State MainApp.routeObserver.unsubscribe(this); WidgetsBinding.instance.removeObserver(this); GStorage.close(); - EventBus().off(EventName.loginEvent); PiliScheme.listener?.cancel(); super.dispose(); } diff --git a/lib/utils/event_bus.dart b/lib/utils/event_bus.dart deleted file mode 100644 index 67b6df8d..00000000 --- a/lib/utils/event_bus.dart +++ /dev/null @@ -1,53 +0,0 @@ -// 订阅者回调签名 -typedef EventCallback = void Function(dynamic arg); - -class EventBus { - // 私有构造函数 - EventBus._internal(); - - // 保存单例 - static final EventBus _singleton = EventBus._internal(); - - // 工厂构造函数 - factory EventBus() => _singleton; - - // 保存事件订阅者队列,key:事件名(id),value: 对应事件的订阅者队列 - final _emap = >{}; - - // 添加订阅者 - void on(eventName, EventCallback f) { - _emap[eventName] ??= []; - _emap[eventName]!.add(f); - } - - // 移除订阅者 - void off(eventName, [EventCallback? f]) { - var list = _emap[eventName]; - if (eventName == null || list == null) return; - if (f == null) { - _emap[eventName] = []; - } else { - list.remove(f); - } - } - - // 触发事件,事件触发后该事件所有订阅者会被调用 - void emit(eventName, [arg]) { - var list = _emap[eventName]; - if (list == null) return; - List tempList = List.from(list); - for (var callback in tempList) { - callback(arg); - } - } - - // 获取订阅者数量 - int getSubscriberCount(eventName) { - var list = _emap[eventName]; - return list?.length ?? 0; - } -} - -class EventName { - static const String loginEvent = 'loginEvent'; -}