extendTag in Dart custom element

Issue

from this link in javascript, customs element extending button is made as:

var MegaButton = document.registerElement('mega-button', {
  prototype: Object.create(HTMLButtonElement.prototype),
  extends: 'button'
});

<button is="mega-button">

I tried making the same using dart, by this code:

class MegaButton extends ButtonElement  {
static final tag = 'mega-button';
factory MegaButton()=>new Element.tag('button', tag);  
   MegaButton.created() : super.created() { 
       var shadow = this.createShadowRoot();
       shadow.text='save';
  }
}
 document.registerElement(MegaButton.tag, MegaButton);

in the html file

    <button  is="mega-button"></button>
    <mega-button>click me</mega-button>

but got this error:

Exception: Unsupported operation: Class must provide extendsTag if base native class is not HTMLElement

any help pls. thanks

Solution

document.registerElement should look like:

document.registerElement(MegaButton.tag, MegaButton, extendsTag: 'button');
=> new Element.tag('button', tag);

see also Custom Polymer element extending AElement in Dart

Answered By – Günter Zöchbauer

Answer Checked By – Pedro (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *