event-listener-container

Manage event subscription lifecycles in Flutter plugin views with EventListenerContainer.

70|12|Updated Apr 1, 2025
One-click install
npx skills add https://github.com/hunmer/Memento --skill event-listener-container
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: event-listener-container
Source: https://github.com/hunmer/Memento/tree/main/.claude/skills/event-listener-container
Command: npx skills add https://github.com/hunmer/Memento --skill event-listener-container

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

为Flutter插件视图自动管理事件订阅,避免手动订阅带来的内存泄漏和重复模板代码。

Core Features & Use Cases

  • 自动管理事件订阅生命周期:在需要响应全局事件的 UI 区域自动订阅和取消订阅。
  • 将 UI 包裹在 EventListenerContainer 中,简化事件驱动的界面更新。
  • 与 AnimatedBuilder 等控制器组合使用,支持多监听器并减少样板代码。

Quick Start

Import the widget and wrap your UI with EventListenerContainer.

  • Import: package:Memento/widgets/event_listener_container.dart
  • Wrap: EventListenerContainer( events: ['data_changed', 'theme_changed'], onEvent: () => setState(() {}), child: MyContentWidget(), )

Frequently Asked Questions about event-listener-container

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent memory leaks from event subscriptions in Flutter widgets?

To prevent memory leaks from event subscriptions in Flutter widgets, wrap your UI in EventListenerContainer. It automatically handles subscription disposal when the widget is removed from the tree, eliminating manual cleanup boilerplate.

How do I set up automatic event subscription management in a Flutter plugin view?

To set up automatic event subscription management, import the event listener container widget and wrap your target UI. Provide a list of event names and an onEvent callback to trigger UI updates like setState when global events occur.

Can I listen to multiple global events independently in Flutter without writing repetitive code?

Yes, you can listen to multiple global events independently by passing an array of event strings to the container. It supports multiple independent listeners while reducing boilerplate code for event-driven interface updates.

Does EventListenerContainer work with other Flutter controllers like AnimatedBuilder?

Yes, EventListenerContainer works with controllers like AnimatedBuilder. You can combine them to support multiple listeners and reduce boilerplate, allowing your UI components to react to global events and animations simultaneously.

What is the best way to auto-dispose Dart event listeners in Flutter?

The best way to auto-dispose Dart event listeners in Flutter is using a container widget that manages the subscription lifecycle. It automatically cancels subscriptions when the widget is destroyed, preventing memory leaks and reducing manual disposal errors.