I have the following class:
class EventableNumber{
num _val;
num get val => _val;
void set val(num v){
num oldValue = _val;
_val = v;
_controller.add(new NumberChangedEvent(oldValue, v));
}
StreamController<NumberChangedEvent> _controller = new StreamController<NumberChangedEvent>();
Stream<NumberChangedEvent> _stream;
Stream<NumberChangedEvent> get onChange => (_stream != null) ? _stream : _stream = _controller.stream.asBroadcastStream();
EventableNumber([num this._val = 0]);
}
Is it possible to overload the =
assignment operator? rather than using the val
getter and setter to enforce the event to fire when the value changes it would be nice if it could just be done when the user writes myEventableNum = 34
and then myEventableNum
first its onChange
event, rather than myEventableNum.val = 34
.