Can Dart bind to id attribute?

Issue

I need to generate a list of radio button inputs from a List, and to link the <label for="xx"> tag to the <input>, each needs its own id.

But it seems Dart cannot bind to an id attribute:

<div id="{{s}}">
  <p id="text">{{s}}</p> <!-- Works as expected -->
</div>

The above results in the error:

Error: line 40 pos 22: illegal use of class name ‘DivElement’ autogenerated_html.DivElement __{{s}};

So my question is: Can Dart bind to an id attribute, and if so how?

And an alternative question: Is there another way to use web_ui generate a list of radio button inputs with labels?

Solution

As your example shows, the web ui compiler uses IDs in a very special way. The compiler assumes they are string constants, and uses them to generate fields and local variable names and also to query for the element in the generated code.

I’d say this is a bug/feature request that should be addressed somehow in web_ui. You can follow progress on this issue here: https://github.com/dart-lang/web-ui/issues/284

Answered By – Siggi Cherem

Answer Checked By – Mildred Charles (FlutterFixes Admin)

Leave a Reply

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