1234567891011121314151617181920212223242526272829303132333435363738 |
- import 'package:fis_jsonrpc/services/notification.m.dart';
- import 'package:flutter/foundation.dart';
- import 'core/interface/handler.dart';
- abstract class NotificationHandler<T>
- implements IHandler<T>, IDistributable<T> {
- final Set<ValueChanged<T>> _distributeCbList = {};
- /// 通知类型枚举
- final NotificationTypeEnum type;
- NotificationHandler(this.type);
- @override
- int get typeInt => type.index;
- @override
- @protected
- @mustCallSuper
- void execute(T message) {
- if (_distributeCbList.isNotEmpty) {
- for (final cb in _distributeCbList) {
- cb.call(message);
- }
- }
- }
- @override
- void subscribe(ValueChanged<T> callback) {
- _distributeCbList.add(callback);
- }
- @override
- void unsubscribe(ValueChanged<T> callback) {
- _distributeCbList.remove(callback);
- }
- }
|