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

插件详情v1.0.1

eventify

一个可取消的事件发射器,支持基于上下文的事件驱动编程。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
12.3万
喜欢数
47
Pub 分数
150

安装插件

flutter pub add eventify

插件介绍

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

Eventify 是一个可取消的事件发射器,专为 Dart 中的上下文感知、事件驱动编程而设计。它通过内置的取消支持,允许事件的发出和监听,实现组件间的高效通信,确保不会出现内存泄漏。非常适合用于管理应用不同部分的状态变化、用户交互或异步工作流。该包支持所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux,使其在跨平台开发中具有高度的通用性。

适合场景

  • 实时通知
  • 复杂用户界面中的状态管理
  • 将业务逻辑与用户界面分离
  • 跨屏幕处理用户交互
  • 管理小部件中的生命周期事件
  • 在服务之间广播消息

主要特点

  • 可取消的事件监听器
  • 上下文感知事件处理
  • 跨平台兼容性
  • 轻量且快速
  • 支持异步事件处理
  • 订阅和发布使用的简洁 API

适合对象

  • 开发响应式应用程序的开发者
  • 使用事件驱动架构的团队
  • 需要干净组件解耦的项目
  • 具有复杂状态流的应用程序
  • Flutter 应用需要可靠的事件广播
  • 开发者避免回调地狱

使用建议

  • 需要仔细管理订阅以避免意外行为
  • 在没有节流的情况下,不适合高频事件流
  • 在非常简单的用例中可能会引入开销
  • 最适合中大型应用
  • 需要理解事件生命周期和取消模式

原始 README

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

EventEmitter

EventEmitter for dart. This can be used in any application to register for events and get notified once it is fired.


This library provide mechanism to register for event notifications with emitter or publisher and get notified in the event of an event.

One main advantage of the mehanism is that, it support context from where the subscriber is listening. The context could be any additional data the subscriber is interested in.

Another feature this has is the ability to receive sender information, which could be handy if the subscriber wish to know about the publisher.

Example

    void performAddition(){

    }

    EventCallback cb = (ev, cont) {
        if (null != ev) {
          switch (ev.eventName) {
            case "add":
              performAddition();
              break;
          }
        }
      };

    EventEmitter emitter = new EventEmitter();
    Listener listener = emitter.on("add", this , cb);

    emitter.emit("add","keyboard",10);


As shown in the above example, it is easy to register for events and get notified once it is triggered.

所属分类

源码仓库

使用此插件的项目