Problem: I have a dart file defining some data structures, which I need to use both for the client and for the server. I\'d like to make these data structures o
You can use the observe
package.
With ChangeNotifier
you initiate the change notification yourself by calling notifyPropertyChange
when a value changes. The changes get delivered synchronously.
Observable
needs dirtyCheck()
to be called to deliver changes.
Polymer calls Observable.dirtyCheck()
repeatedly to get the changes automatically.
an example for each
import 'package:observe/observe.dart';
class Notifiable extends Object with ChangeNotifier {
String _input = '';
@reflectable
get input => _input;
@reflectable
set input(val) {
_input = notifyPropertyChange(#input, _input, val + " new");
}
Notifiable() {
this.changes.listen((List record) => record.forEach(print));
}
}
class MyObservable extends Observable {
@observable
String counter = '';
MyObservable() {
this.changes.listen((List record) => record.forEach(print));
}
}
void main() {
var x = new MyObservable();
x.counter = "hallo";
Observable.dirtyCheck();
Notifiable notifiable = new Notifiable();
notifiable.input = 'xxx';
notifiable.input = 'yyy';
}