Book Image

Learning Dart, Second Edition - Second Edition

By : Ivo Balbaert
Book Image

Learning Dart, Second Edition - Second Edition

By: Ivo Balbaert

Overview of this book

Table of Contents (18 chapters)
Learning Dart Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Handling events


When the user interacts with the web form, such as while clicking on a button or filling in a text field, an event fires; any element on the page can have events. The DOM contains hooks for these events and the developer can write the code (an event handler) that the browser must execute when the event fires. How do we add an event handler to an element (which is also called registering an event handler)? The general format is (the spaces are not needed, but can be used to make the code more readable):

  element.onEvent.listen( event_handler )

Examples of events are Click, Change, Focus, Drag, MouseDown, Load, KeyUp, and so on. View this as the browser listening to the events on the elements. When they occur, the indicated event handler can be executed. The argument that is passed to the listen() method is a callback function and it has to be of the EventListener type; it has the void EventListener(Event e) signature.

The event handler gets passed via an Event parameter, succinctly...