搜索插件、代码仓与 APP 分类

插件详情v0.7.0

event_bus_plus

Dart 的事件总线。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
5220
喜欢数
40
Pub 分数
130

安装插件

flutter pub add event_bus_plus

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

EventBusPlus 是 Dart 的轻量级事件总线实现,可在 Flutter 应用中实现对象之间的简单高效通信。它支持类型安全的事件广播和订阅,非常适合在不产生紧密依赖的情况下解耦组件。该包设计简洁易用,提供清晰的 API,使开发者能够轻松地在应用的不同部分发出事件并监听它们。它可无缝运行于所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux。

适合场景

  • 解耦UI组件
  • 处理跨小部件通信
  • 管理应用范围内的状态更改
  • 简化导航事件
  • 广播通知
  • 实现插件事件系统

主要特点

  • 类型安全的事件处理
  • 简单的订阅和发射 API
  • 跨平台兼容性
  • 轻量且开销极小
  • 支持事件取消
  • 简洁直观的语法

适合对象

  • 寻求轻量级状态管理的开发者
  • 频繁组件间通信的应用程序
  • 项目避免复杂的状态解决方案
  • 偏好发布-订阅模式的团队
  • 快速原型开发事件驱动功能

使用建议

  • 不适合大规模状态管理
  • 有限的内置错误处理
  • 无持久化或序列化支持
  • 最好与其他状态管理方法配合使用
  • 可能需要仔细清理以避免内存泄漏

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

EventBus: Events for Dart/Flutter

pub package codecov Dart

EventBus is an open-source library for Dart and Flutter using the publisher/subscriber pattern for loose coupling. EventBus enables central communication to decoupled classes with just a few lines of code – simplifying the code, removing dependencies, and speeding up app development.

event bus publish subscribe

Your benefits using EventBus: It…

  • simplifies the communication between components;
  • decouples event senders and receivers;
  • performs well with UI artifacts (e.g. Widgets, Controllers);
  • avoids complex and error-prone dependencies and life cycle issues.
event bus plus
Define the app's events
// Initialize the Service Bus
IAppEventBus eventBus = AppEventBus();

// Define your app events
final event = FollowEvent('@devcraft.ninja');
final event = CommentEvent('Awesome package 😎');
Subscribe
// listen the latest event
final sub = eventBus.last$
        .listen((AppEvent event) { /*do something*/ });

// Listen particular event
final sub2 = eventBus.on<FollowAppEvent>()
        .listen((e) { /*do something*/ });
Publish
// fire the event
eventBus.fire(event);
Watch events in progress
// start watch the event till its completion
eventBus.watch(event);

// and check the progress
eventBus.isInProgress<FollowAppEvent>();

// or listen stream to check the processing
eventBus.inProgress$.map((List<AppEvent> events) =>
        events.whereType<FollowAppEvent>().isNotEmpty);

// complete
_eventBus.complete(event);

// or complete with completion event
_eventBus.complete(event, nextEvent: SomeAnotherEvent);

History

final events = eventBus.history;

Mapping

final eventBus = bus = EventBus(
        map: {
          SomeEvent: [
            (e) => SomeAnotherEvent(),
          ],
        },
      );

Contributing

We accept the following contributions:

Maintainers

  • [Andrew Piterov](mailto:contact@andrewpiterov.com?subject=[GitHub]%20Source%20Dart%event_bus_plus)

所属分类

依赖

依赖清单 4 项

源码仓库

使用此插件的项目