搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案