Book Image

DART Cookbook

By : Ivo Balbaert
Book Image

DART Cookbook

By: Ivo Balbaert

Overview of this book

Table of Contents (18 chapters)
Dart Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Event handling


In this recipe, we will show you how to handle events in a Polymer component. You can find the code in the project event_handling.

How to do it...

  1. The script starts with web\index.html, where a component with the name pol-select is imported through the following line:

    <link rel="import"href="pol_events.html">

    From this, we know that the component is defined in pol_events.html, and the code behind it is in a file named pol_events.dart. For a discussion of the other tags, refer to the first recipe.

  2. The code for pol-events is defined in pol_events.dart:

    import'package:polymer/polymer.dart';
    
    @CustomTag('pol-events')
    classPolevents extends PolymerElement {
    @observable String which_event = "no event";
    @observable String thing = "";
    @observable String message = "";
    
    Polevents.created() : super.created();
    
    enter(KeyboardEvent  e, var detail, Node target) {
      if (e.keyCode == KeyCode.ENTER) {
      which_event = "you pressed the ENTER key";
      }
    }
    
    btnclick(MouseEvent  e, var detail, Node...