I am trying to create a custom element in dart HTML and this answer shows how to do so but it uses a deprecated API so my question is how can I do that today? my code:
class HelloWorld extends HtmlElement {
static final tag = 'hello-world';
factory HelloWorld() {
var self = Element.tag(tag);
var shadow = self.attachShadow({'mode': 'open'});
shadow.children = [
HRElement()..style.width = '50%',
ParagraphElement()..text = 'hello world',
HRElement()..style.width = '80%',
];
return self;
}
HelloWorld.created() : super.created();
}
void main() {
document.registerElement(HelloWorld.tag, HelloWorld);
}
the error:
Uncaught Error: Invalid argument(s): HelloWorld
at Object.throw_ [as throw] (dart_sdk.js:3879)
at Object._registerCustomElement (dart_sdk.js:98068)
at HTMLDocument.[dartx.registerElement2] (dart_sdk.js:75054)
at HTMLDocument.[dartx.registerElement] (dart_sdk.js:70020)
at main$ (main.dart:19)
...