How do I create a canvas element in Dart? How do I create a canvas element in Dart? dart dart

How do I create a canvas element in Dart?


Eventually you'll be able to just do:

new CanvasElement();

The new HTML lib hasn't been fully populated with constructors yet, though. It's a work-in-progress. In the meantime, the easiest way is probably:

new Element.html('<canvas></canvas>');

That will return an instance of CanvasElement.


In Dart, you can create objects directly from an interface (http://www.dartlang.org/docs/getting-started/interface.html) so there is nothing wrong to create canvas using new CanvasElement().