Makes it easier to expose custom events in Dart using the Stream API.
1. Add the following to your project's pubspec.yaml and run
pub install.
dependencies:
event_stream: any
2. Add the correct import for your project.
import 'package:event_stream/event_stream.dart';
import 'package:event_stream/event_stream.dart';
import 'dart:async';
class ClassWithEvents implements NotifyPropertyChanged {
String _someProperty;
final EventStream<PropertyChangedEventArgs> _onPropertyChangedEvent = new EventStream<PropertyChangedEventArgs>();
Stream<PropertyChangedEventArgs> get onPropertyChanged => _onPropertyChangedEvent.stream;
final EventStream _onClosedEvent = new EventStream();
Stream get onClosed => _onClosedEvent.stream;
String get someProperty => _someProperty;
set someProperty(String value) {
_someProperty = value;
_onPropertyChangedEvent.signal(new PropertyChangedEventArgs('someProperty', value));
}
close() {
_onClosedEvent.signal();
}
}
main() {
var c = new ClassWithEvents();
c.onPropertyChanged.listen((PropertyChangedEventArgs<String> args) => print('changed: name=${args.propertyName} value=${args.value}'));
c.onClosed.listen((_) => print('closed'));
c.someProperty = "test";
c.close();
}
Add this to your package's pubspec.yaml file:
dependencies: event_stream: 0.2.1
If your package is an
application package you should use any
as the
version constraint.
If you're using the Dart Editor, choose:
Menu > Tools > Pub Install
Or if you want to install from the command line, run:
$ pub install
Now in your Dart code, you can use:
import 'package:event_stream/ event_stream.dart';
| Version | Uploaded | Archive |
|---|---|---|
| 0.2.1 | Apr 26, 2013 | Download event_stream 0.2.1 archive |
| 0.1.1 | Jan 31, 2013 | Download event_stream 0.1.1 archive |
| 0.1.0 | Jan 31, 2013 | Download event_stream 0.1.0 archive |