Event handling in DART

I am new to DART. I read a review of the language and checked the sample code in the DART editor. So far, I have not been able to find how to handle events in DART. E.g. OnClick = "call_dart_method ()".

How can we handle events in DART?

+6
source share
2 answers

This is not how you do it on Dart Check here in the Events section: http://www.dartlang.org/articles/improving-the-dom/

elem.onClick.listen( (event) => print('click!')); 
+4
source

In addition, you may find that the ability to optionally declare our variable types does work with events in Dart bliss.

 import 'dart:html'; import 'dart:math'; class MyApplication { MyApplication() { CanvasElement screenCanvas; CanvasRenderingContext2D screen; final int WIDTH = 400, HEIGHT = 300; Random rand = new Random(); screenCanvas = new CanvasElement(); screenCanvas ..width = WIDTH ..height = HEIGHT ..style.border = 'solid black 1px'; screen = screenCanvas.getContext('2d'); document.body.nodes.add(screenCanvas); screenCanvas.onClick.listen((MouseEvent me) { int r = rand.nextInt(256), g = rand.nextInt(256), b = rand.nextInt(256); double a = rand.nextDouble(); screen ..save() ..translate(me.offsetX, me.offsetY) ..rotate(rand.nextDouble() * PI) ..fillStyle = 'rgba($r,$g,$b,$a)' ..fillRect(-25, -25, 50, 50) ..restore(); }); } } void main() { new MyApplication(); } 
+4
source

Source: https://habr.com/ru/post/913452/


All Articles