flutter EventBus

#配置文件中 先 引入

event_bus: ^2.0.0

1.封装一个类 便于直接调用
Dart 复制代码
import 'package:event_bus/event_bus.dart';
class EvenBlueUtil{

  static EventBus eventBus = EventBus();

  static EventBus eventBusUpdate = EventBus();

}

class UserLoggedInEvent {

  var user;

  UserLoggedInEvent(this.user);

}

class NewOrderEvent {

  var order;
  NewOrderEvent(this.order);

}
2.使用方法
Dart 复制代码
//可以传值也可以不传值 括号类型可以放入自己想要的信息
EvenBlueUtil.eventBus.fire(null);
3.在需要接受页面的消息进行注册

StreamSubscription? subscription;

从even可以接收传递的信息

Dart 复制代码
 @override
  void initState() {
    super.initState();
    _controller = EasyRefreshController(
    
    subscription = EvenBlueUtil.eventBus.on().listen((event) {
      
      print("消费!!!!!!");
      
     
    });
  }

  @override
  void dispose() {
    
    super.dispose();
    subscription!.cancel();
  }

//注意 离开页面会被销毁,会接收不到 但是跳转页面不会,比如跳转页面进行修改,然后返回页面是可以的,但是 点击底部菜单栏从 首页,我的来回切换是不可以的

相关推荐
qqacj3 分钟前
Spring Security 官网文档学习
java·学习·spring
Rsun0455114 分钟前
10、Java 桥接模式从入门到实战
java·开发语言·桥接模式
于慨14 分钟前
mac安装flutter
javascript·flutter·macos
金銀銅鐵16 分钟前
[Java] 从 class 文件看 cglib 对 MethodInterceptor 的处理 (下)
java·后端
lee_curry18 分钟前
Java中关于“锁”的那些事
java·线程·并发·juc
pearlthriving25 分钟前
c++当中的泛型思想以及c++11部分新特性
java·开发语言·c++
安卓程序员_谢伟光31 分钟前
m3颜色定义
android·compose
梦魇星虹1 小时前
idea Cannot find declaration to go to
java·ide·intellij-idea
2601_949593651 小时前
Flutter_OpenHarmony_三方库_image_picker图片视频采集适配详解
flutter·音视频
小雅痞1 小时前
[Java][Leetcode hard] 42. 接雨水
java·开发语言·leetcode