flutter_easybus

Last updated:

0 purchases

flutter_easybus Image
flutter_easybus Images
Add to Cart

Description:

flutter easybus

flutter_easybus #
flutter 订阅通信总线
Getting Started #
This project is a starting point for a Dart
package,
a library module containing code that can be shared easily across
multiple Flutter or Dart projects.
For help getting started with Flutter, view our
online documentation, which offers tutorials,
samples, guidance on mobile development, and a full API reference.
基础使用
定义任意订阅对象
class BusTest{
late Map bus;
BusTest({required this.bus});
}
copied to clipboard
注册订阅
第一种(推荐)
EventSubscription subscription= EasyBus().on<BusTest>().listen((arg) {
print("normal listen ${arg.bus}" );
});
//subscription.free();///在合适的位置释放 防止内存泄露
copied to clipboard
第二种
/// 注意使用wait 方法订阅在第一次回调会自动销毁
var busTest= await EasyBus().on<BusTest>().wait();
print("wait listen ${busTest.bus}");
copied to clipboard
发送信息
EasyBus().send(BusTest(bus: {'name':'easyBus'}));
copied to clipboard
注销所有当前对象订阅
EasyBus().free<BusTest>();
copied to clipboard
有没有更简单的使用方法
EasyBus().simpleOn().listen((arg) { ///直接使用内置对象
print("simple listen ${arg.key}" );
});

/// 发送信息
EasyBus().simpleSend("key123", {'name':'lisa'});
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.