How to subscribe to change of an observable field


until lately I could use bindProperty like shown below or in this question, but that has changed with 0.8.0 and I don’t know how to change my code to get the old behaviour (doSomething() gets called):

<polymer-element name="my-login" attributes="model">
    <template if="{{"model.isLoggedIn}}">
  <script type= ... ></script>


class MyLogin extends PolymerElement with ObservableMixin {
  LoginModel model;

  inserted() {

  void doSomething() {

logoutChangeSubscription = bindProperty(model, #isLoggedIn, () => doSomething());


class Model extends Object with ObservableMixin {
  @observable bool isLoggedIn = false;


With Polymer.dart 0.8 or greater, you can also use this convenience form:

isLoggedInChanged(oldValue) {

Notice how you can create a method inside your PolymerElement that uses a name of yourFieldName*Changed

There’s also onPropertyChange as defined here:

From the docs:

class MyModel extends ObservableBase {
  StreamSubscription _sub;
  MyOtherModel _otherModel;

  MyModel() {
    _sub = onPropertyChange(_otherModel, const Symbol('value'),
        () => notifyProperty(this, const Symbol('prop'));

  String get prop => _otherModel.value;
  set prop(String value) { _otherModel.value = value; }

Answered By – Seth Ladd

Answer Checked By – Senaida (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.