title: Flutter Provider: How do I listen to a change of a class field inside a class field?
body: <p>Given the following Dart/Flutter class structure:</p>
  
  <pre class="lang-dart prettyprint-override"><code>import 'package:flutter/material.dart';
  
  class A with ChangeNotifier {
    B _element1;
    B _element2;
  
    B get element1 =&gt; _element1;
    B get element2 =&gt; _element2;
  
    set element1(B value) {
      _element1 = value;
      notifyListeners();
    }
  
    set element2(B value) {
      _element2 = value;
      notifyListeners();
    }
  }
  
  class B {
    String x;
    String y;
  }
  </code></pre>
  
  <p>I am trying to listen to a change of <code>A.element1.x</code> but the problem is, the setter of class B can't call the <code>notifyListeners()</code> of the class A, so either I am Listening to A and won't notice a change or I am listening to B and I am losing the context to A.</p>
  
  <p>I am using the Provider package in my Flutter project. But I am not sure, if I am misunderstanding the concept of Provider package or ChangeListeners. Either way I am not able to find a elegant solution.</p>
  
  <p>Is there a possibility to overwrite the setter of class B from class A?
  I could obviously implement a function for each element1 and element2 fields(x,y). But this is not good code style I guess.</p>