当前位置:网站首页>flutter EventBus
flutter EventBus
2022-07-18 11:32:00 【Dense breath】
Define this eventbus Tools
You can define events in it
import 'dart:async';
import 'package:event_bus/event_bus.dart';
import 'package:flutter/material.dart';
import 'package:social_im/models/im_customInfo_model.dart';
import 'package:social_im/pages/IMCCalling/ui/base/CallTypes.dart';
import 'package:social_im/pages/IMCCalling/ui/base/CallingScenes.dart';
import 'package:tencent_im_sdk_plugin/models/v2_tim_conversation.dart';
class EventBusUtil {
static EventBus? _eventBus;
// Access to the singleton
static EventBus getInstance() {
if (_eventBus == null) {
_eventBus = EventBus();
}
return _eventBus!;
}
// Return the subscriber of an event
static StreamSubscription<T> listen<T extends Event>(
Function(T event) onData) {
if (_eventBus == null) {
_eventBus = EventBus();
}
// The internal stream belongs to broadcast mode , There can be multiple subscribers
return _eventBus!.on<T>().listen(onData);
}
// Send events
static void fire<T extends Event>(T e) {
if (_eventBus == null) {
_eventBus = EventBus();
}
_eventBus!.fire(e);
}
}
abstract class Event {
}
class LoginEvent extends Event {
static int eventIn = 1;
static int eventOut = 0;
static int onKickedOffline = 2;
static int onUserSigExpired = 3;
final int status;
LoginEvent(this.status);
}
class LoginSuccessdEvent extends Event {
}
class MomentListEvent extends Event {
}
class ObtainingLocationPermissionEvent extends Event {
}
class PhotoListEvent extends Event {
int photoType = 0;
///0 Upload 1 Delete
PhotoListEvent(this.photoType);
}
class PhotoPayEvent extends Event {
int photoId = 0;
PhotoPayEvent(this.photoId);
}
class VideoListEvent extends Event {
int videoType = 0;
///0 Upload 1 Delete
VideoListEvent(this.videoType);
}
class VideoPayEvent extends Event {
int videoId = 0;
VideoPayEvent(this.videoId);
}
class StowKeyboardEvent extends Event {
}
class MomentEvent extends Event {
final bool? isLike;
final int? commentCount;
final int? likeCount;
MomentEvent({
this.isLike, this.commentCount, this.likeCount});
}
class MessageNoticeEvent extends Event {
final int? messageType;
final int? messageNum;
final int? activityType;
MessageNoticeEvent({
this.messageType, this.messageNum,this.activityType});
}
class MessageEvent extends Event {
final V2TimConversation v2timConversation;
MessageEvent({
required this.v2timConversation});
}
class CallingVideoEvent extends Event {
final CallingScenes callingVideoType;
CallingVideoEvent({
required this.callingVideoType});
}
class ScreeningNearbyEvent extends Event {
RangeValues? rangeValues;
int? checkType;
ScreeningNearbyEvent({
this.rangeValues, this.checkType});
}
class ImCustomInfoEvent extends Event {
ImCustomInfoModel? imCustomInfoModel;
ImCustomInfoEvent(this.imCustomInfoModel);
}
class MatchDialogEvent extends Event {
int matchType;
int matchUserId;
int playType;
MatchDialogEvent(this.matchType, this.matchUserId, this.playType);
}
class MatchPayNumDialogEvent extends Event {
Map<String, dynamic> payData;
MatchPayNumDialogEvent(this.payData);
}
class ShakeCloseDialogEvent extends Event{
bool isClose;
ShakeCloseDialogEvent(this.isClose);
}
class IsCanShakeEvent extends Event{
bool isCanShake;
IsCanShakeEvent(this.isCanShake);
}
Use :
Publisher
// If the threshold is reached ,EventBus Release the news , Let the result pop up and return to the interface , Shake it again
EventBusUtil.fire(ShakeCloseDialogEvent(true));
subscriber
late StreamSubscription<ShakeCloseDialogEvent> _shakeCloseDialogEvent;
@override
void initState() {
// TODO: implement initState
_shakeCloseDialogEvent = EventBusUtil.listen((event) {
// Keep monitoring , If you receive true Return to the interface
if (event.isClose) {
Navigator.pop(context, true);
}
});
super.initState();
}
@override
void dispose() {
// TODO: implement dispose
_shakeCloseDialogEvent.cancel();// Cancel
super.dispose();
}
边栏推荐
- C: Free (): thinking about invalid pointer abort (core dump)
- mosquitto. H learning
- Shenzhen has launched a pilot project of online signing of construction contracts, and France has greatly contributed to building digitalization
- 曲伟海:坚持选择不放弃 是实现初心的法宝
- Filter
- Envoy monitoring management
- Double thread guessing numbers
- 【开发教程6】疯壳·开源蓝牙智能健康手表-触摸
- Flink (III) processing function
- 【Flink】Flink Connection拒绝:localhost / 127.0.0.1:8081
猜你喜欢

剑指 Offer 55 - II. 平衡二叉树

Experiment 3 servlet related technology

Flink(五)状态编程

Sword finger offer 68 - I. nearest common ancestor of binary search tree

02、RestTemplate学习笔记

wireshark使用

Tcmalloc learning
![[Flink] Flink connection reject: localhost / 127.0.0.1:8081](/img/46/6c5071016a04e511f1bbb9fe3f7643.jpg)
[Flink] Flink connection reject: localhost / 127.0.0.1:8081

IP static routing comprehensive experiment

Talking about software defect management
随机推荐
Experiment 3 servlet related technology
编辑距离问题
EMQX 服务器建立SSL/TLS安全连接、单向、双向
Flink(六)容错机制
Power system unit commitment (realized by matlab code)
【踩坑】Appending a row → DataFrame
Flink (III) processing function
剑指 Offer 55 - II. 平衡二叉树
[unity3d] toggle of ugui
Ping message and ICMP message header
thinkphp5 读取多行文本、读取文件分割多行文本
Process, thread, multiplexing
Acceptance test experiment based on fitness
Happy event, a long planned new era of shopping
Tcmalloc learning
Wireshark packet capturing debugging (three-way handshake, four-way disconnection)
wireshark 抓包调试(三路握手、四路断开)
flutter 生命周期
Envoy监听管理
现货黄金走势图中三条均线的秘密