event_taxi 1.0.0 copy "event_taxi: ^1.0.0" to clipboard
event_taxi: ^1.0.0 copied to clipboard

EventTaxi could be used to send events through different layers of the application decoupled from the architecture.

example/event_taxi_example.dart

import 'package:event_taxi/event_taxi.dart';
import 'package:event_taxi/src/event.dart';

class TodoCreated implements Event {
  final String name;
  final String description;

  TodoCreated({required this.name, required this.description});
}

class UserLoggedIn implements Event {
  final String username;

  UserLoggedIn({required this.username});
}

main() {
  EventTaxi eventBus = EventTaxiImpl();

  eventBus.registerTo<TodoCreated>().listen((event) {
    // handle event
    print("to created: name=${event.name}, description=${event.description}");
  });

  eventBus.fire(TodoCreated(
      name: "create example",
      description: "add example for this cool libary called EventTaxi 🚕."));

  // additionally you can also register and immediately receive the previous event
  eventBus.fire((UserLoggedIn(username: "Stefan")));

  eventBus.registerTo<UserLoggedIn>(true).listen((event) {
    // prints "Stefan" and then "Tobi"
    print(event.username);
  });

  eventBus.fire(UserLoggedIn(username: "Tobi"));
}
7
likes
150
points
152
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

EventTaxi could be used to send events through different layers of the application decoupled from the architecture.

Repository (GitHub)
View/report issues

License

Apache-2.0 (license)

Dependencies

meta

More

Packages that depend on event_taxi