What does "unresolved implicit superconstructor call" mean in dart language?

What this example looks like:

import "dart:html";

class SubMenuElement extends DivElement {

    SubMenuElement() {
        print("my element created");
    }

}

Gives an error:

Internal error: 'file.dart': error: line x pos y: unresolved implicit call to super constructor 'DivElement()'
    SubMenuElement() {
                  ^

What does the error message mean and how will the working example work?

+3
source share
3 answers

You can declare a subclass of DivElement as follows:

import 'dart:html';

class MyDiv extends DivElement {
  factory MyDiv() => new Element.tag('div', 'my-div');
  MyDiv.created() : super.created();
}

A factory constructor is not required, but it is convenient if you want to build instances imperatively.

Then you must register your custom element with the document before you can create it:

main() {
  document.register('my-div', MyDiv, extendsTag: 'div');
  document.body.append(new MyDiv()..text = 'Hello');
}

Dartium , Custom Elements (, Chrome 33+). polyfill. pubspec:

dependencies:
  custom_element: '>=0.9.0'
  ...

pub get polyfill script html:

<body>    
  <script src="packages/custom_element/custom-elements.min.js"></script>
  ...
</body>
+2

DivElement . .

SubMenuElement.created() : super.created();

DOM, with Polymer

import 'dart:html';
import 'package:polymer/polymer.dart';

class SubMenuElement extends DivElement with Polymer {
  SubMenuElement.created() : super.created();
}

, Polymer, Polymer, , .

+3

, DivElement() . , .

However, DivElement cannot be subclassed directly. But you can mimic this behavior by implementing DivElement, rather than expanding it and delegating each call:

class MyDivElement implements DivElement {

  DivElement _delegate;

  MyDivElement() {
    _delegate = new DivElement();
    // whatever else should happen in your constructor
  }

  // For best performance, every member SHOULD be implemented explicitly.
  String get text => _delegate.text;
  Node get parentNode => _delegate.parentNode;
  ShadowRoot get shadowRoot => _delegate.shadowRoot;

  // But DivElement has a lot of members.
  // Unused or rarely used members could also be delegated with reflection.
  noSuchMethod(Invocation invocation) => reflect(_delegate).delegate(invocation);

}
+2
source

All Articles