API Reference 0.7.1rikulo_eventViewEvent

ViewEvent class

A view event. The event received by View's event listener must be an instance of this class.

Notice that the event will bubble up through the hierarchy of views. It is convenient if you'd like to handle the events of children. For example, you can handle the click event for all child buttons as follows:

view.on.click((event) {
  switch (event.target.id) { //target is the view firing the event
    case "OK": //submit
    case "Cancel": //...
  }
});

Sometimes it might cause a problem. For example, LayoutEvent will be sent to every views and then bubbles up. It means your layout listener usually has to filter events not belonging to the target view. It can be done easily by use `event.target == event.currentTarget'. For example,

view.on.layout((event) {
  if (event.target == event.currentTarget) {
     //handle event.target
  }
})
class ViewEvent {
 final String _type;
 final int _stamp;
 bool _propStop = false;

 /** Constructor.
  *
  * + [type] is the event type, such as click.
  * + [target] is the view that this event is targeting. If not specified, it will
  * be assigned automatically when the sendEvent method is called.
  */
 ViewEvent(String type, [View target]):
 _type = type, _stamp = new DateTime.now().millisecondsSinceEpoch {
   this.target = currentTarget = target;
 }
 /** Constructor for subclass. */
 ViewEvent._(this._type, View target): _stamp = 0 {
   this.target = currentTarget = target;
 }

 /** Returns the view that this event is targeting  to.
  */
 View target;
 /** The view that is handling this event currently.
  */
 View currentTarget;

 /** Returns the time stamp.
  */
 int get timeStamp => _stamp;
 /** Returns the event's type. */
 String get type => _type;

 /** Returns whether this event's propagation is stopped.
  *
  * Default: false.
  *
  * It becomes true if [stopPropagation] is called,
  * and then all remaining event listeners are ignored.
  */
 bool get isPropagationStopped => _propStop;
 /** Stops the propagation.
  *Once called, all remaining event listeners, if any, are ignored.
  */
 void stopPropagation() {
   _propStop = true;
 }
 /** Prevents the browser's default behavior.
  */
 void preventDefault() {
 }
 @override
 String toString() => "ViewEvent($target,$type)";
}

Subclasses

ActivateEvent, ChangeEvent<T>, DomEvent, LayoutEvent, ScrollEvent, SelectEvent<T>

Constructors

new ViewEvent(String type, [View target]) #

Constructor.

  • type is the event type, such as click.
  • target is the view that this event is targeting. If not specified, it will be assigned automatically when the sendEvent method is called.

ViewEvent(String type, [View target]):
_type = type, _stamp = new DateTime.now().millisecondsSinceEpoch {
 this.target = currentTarget = target;
}

Properties

View currentTarget #

The view that is handling this event currently.

View currentTarget

final bool isPropagationStopped #

Returns whether this event's propagation is stopped.

Default: false.

It becomes true if stopPropagation is called, and then all remaining event listeners are ignored.

bool get isPropagationStopped => _propStop;

View target #

Returns the view that this event is targeting to.

View target

final int timeStamp #

Returns the time stamp.

int get timeStamp => _stamp;

final String type #

Returns the event's type.

String get type => _type;

Methods

void preventDefault() #

Prevents the browser's default behavior.

void preventDefault() {
}

void stopPropagation() #

Stops the propagation. Once called, all remaining event listeners, if any, are ignored.

void stopPropagation() {
 _propStop = true;
}

String toString() #

Returns a string representation of this object.

docs inherited from Object
@override
String toString() => "ViewEvent($target,$type)";