philiprehberger_event_bus 0.1.0 copy "philiprehberger_event_bus: ^0.1.0" to clipboard
philiprehberger_event_bus: ^0.1.0 copied to clipboard

Typed event bus with Stream subscriptions, sticky events, and scoped lifecycle

example/example.dart

import 'package:philiprehberger_event_bus/philiprehberger_event_bus.dart';

class UserLoggedIn {
  final String userId;
  UserLoggedIn(this.userId);
}

class ItemAdded {
  final String item;
  ItemAdded(this.item);
}

void main() async {
  final bus = EventBus();

  // Type-safe subscriptions
  bus.on<UserLoggedIn>().listen((event) {
    print('User logged in: ${event.userId}');
  });

  bus.on<ItemAdded>().listen((event) {
    print('Item added: ${event.item}');
  });

  // Fire events
  bus.fire(UserLoggedIn('user-123'));
  bus.fire(ItemAdded('Widget'));

  // Sticky events
  bus.fireSticky(UserLoggedIn('user-456'));
  print('Last sticky: ${bus.lastSticky<UserLoggedIn>()?.userId}');

  // Clean up
  await Future<void>.delayed(Duration(milliseconds: 100));
  bus.dispose();
}
1
likes
160
points
0
downloads

Documentation

API reference

Publisher

verified publisherphiliprehberger.com

Weekly Downloads

Typed event bus with Stream subscriptions, sticky events, and scoped lifecycle

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

More

Packages that depend on philiprehberger_event_bus