24/06/16 08:39:19.15 u7far7aY0.net
>>139
import 'dart:async';
class A {
A(this.str){
sc.add(str);
}
String str;
StreamController sc = StreamController()..stream.listen((newValue){
print(newValue);
});
void setAndNotify(String str){
this.str = str;
sc.add(str);
}
}
Future<void> wait() async {
await Future.delayed(Duration(seconds: 1));
}
void main() async {
final a = A('test');
await wait();
a.setAndNotify('test2');
await wait();
a.setAndNotify('test3');
await wait();
a.setAndNotify('test4');
}
Dart標準機能のStreamControllerで変更通知してますよね?
UI側はStreamBuilderが用意されているのでそれで変更検知できますよね。
Dart自体に用意されてないのにDartのサードパーティパッケージでできました、とか無いじゃん。
中を覗いたらDartでやってるんでしょ?