I am trying to find a way for this parent \"Persistent\" class to add functionality so that the \"changed\" property becomes true whenever any property of the child object is ch
You can use the ChangeNotifier
class like shown in the answers to this question
Another attempt is to use reflection but this is discouraged especially in the browser.
The above solution uses reflection too but as far as I know the Smoke transformer generates code that replaces the reflective code when you run pub build
.
Only after a call to Observable.dirtyCheck();
a change detection is initiated (for all observable instances).
import 'package:observe/observe.dart';
class Persistent extends Observable {
bool changed = false;
Persistent() : super() {
changes.listen((e) => changed = true);
}
}
class Child extends Persistent {
@observable num number = 1;
}
main() {
Child item = new Child();
item.number = 2;
Observable.dirtyCheck();
assert(item.changed == true);
}