marcojakob / dart-event-bus

An Event Bus using Dart Streams for decoupling applications
MIT License
755 stars 82 forks source link

Can not set type on listen #14

Closed lyquocnam closed 6 years ago

lyquocnam commented 6 years ago

i have code like this:

class AccountPhotoChangeEvent {
  final File file;
  AccountPhotoChangeEvent(this.file);
}

if i try register event like this:

events.on(AccountPhotoChangeEvent).listen((AccountPhotoChangeEvent event) {

});

and error The argument type '(AccountPhotoChangeEvent) → Null' can't be assigned to the parameter type '(dynamic) → void'.

marcojakob commented 6 years ago

I've updated the package for Dart 2.0 and released version 1.0.0 of event_bus on pub. I think this should fix your problem but you will have to change the way you call the on method because the API changed for 1.0.0:

events.on<AccountPhotoChangeEvent>().listen((event) {
   // do something with the event.   
});
lyquocnam commented 6 years ago

flutter's dart standard is 2.0.0-dev.58.0.flutter-f981f09760 can this work ? is see this message: Because hospital depends on event_bus >=1.0.0 which requires SDK version >=2.0.0-dev.67.0 <2.0.0, version solving failed. pub get failed (1) Can you set dependency to 2.0.0-dev.58.0.flutter-f981f09760 comfortable with flutter please ?

marcojakob commented 6 years ago

@lyquocnam You could try to do this with a dependency override: https://www.dartlang.org/tools/pub/dependencies#dependency-overrides

Well, at least I thought this would be possible. It's possible for packages but I don't know if you can override the SDK dependency.

lyquocnam commented 6 years ago

sorry but still not work, i think you should change the minium version of dart requirement to 2.0.0-dev.58.0.flutter-f981f09760 is better

marcojakob commented 6 years ago

I've lowered the dependency to 2.0.0-dev.58.0 can you confirm that this is working now?

lyquocnam commented 6 years ago

ya it work like a charm, thanks author so much !