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

outdated

A starting point for Dart libraries or applications.

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({this.name, this.description});
}

class UserLoggedIn implements Event {
  final String username;

  UserLoggedIn({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
0
pub points
82%
popularity

Publisher

unverified uploader

A starting point for Dart libraries or applications.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

meta

More

Packages that depend on event_taxi