Polymer 1.0 access fields of the Dart objects?

Issue

I have the following example:

main_app.dart

@PolymerRegister('main-app')
class MainApp extends PolymerElement {
    @property
    Tst superTst = new Tst()..field1 = "blablabla"; 
}

class Tst {
  String field1;
}

main_app.html

<dom-module id="main-app">
  <template>
    Teste 
    <span>{{superTst.field1}}</span> 
  </template>
</dom-module>

But, the {{superTst.field1}} does not result in text being shown!

How to access fields of the Dart objects in Polymer 1.0? (from new classes, different Map, List and primitive types)

Solution

The class must extend JsProxy and each member that should be available from Polymer needs the @reflectable annotation. Currently for a getter/setter pair, both need the @reflectable annotation (fixed already but not released AFAIK)

class Tst extends JsProxy {
  @reflectable String field1;
}

If you update the value of field1 use

set('superTst.field1', 'newValue');

to ensure bindings are updated.

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 *