Can I add Dart Web UI bindings to DOM elements created in code?


In the Dart Web UI package, it is possible to create bindings using the {{}} or bind-value syntax. Is this also possible, when DOM elements are created in code?

Something like

new Element.html('<div>Value: {{str}}</div>');


new Element.html('<input type="text" bind-value="str">');

binding an event to str, without manually piecing the strings together?

Note: this question was asked earlier today, but was deleted before it was answered, but I wanted to know the answer, so I’m reposting it.


Quick answer, no.

The bindings need to be processed by the dwc transformer, which converts Web Components and MDV code into “vanilla” Dart and HTML (suitable for compilation to “vanilla” JavaScript).

Generally, you should use <template> tags to instantiate new elements.

An alternative is to wrap these bits of text inside a custom element, which you can transform with dwc and instantiate manually.

Answered By – Seth Ladd

Answer Checked By – Cary Denson (FlutterFixes Admin)

Leave a Reply

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