Flutterやろうよ!!! 5 (483レス)
上下前次1-新
抽出解除 レス栞
139(2): デフォルトの名無しさん (スップ Sd5a-kQwx) [sage] 2024/06/16(日) 04:36:28.60 ID:VstQa1y8d(1/5) AAS
これは恥ずかしい
import 'dart:async';
class A {
String str;
A(this.str);
}
void main() {
final sc = StreamController(sync: true);
sc.stream.listen((e) => print(e.str));
final a = A("StreamControllerに値の変更を検知する機能が!?");
sc.add(a);
a.str = "あります!";
a.str = "あるわけないだろdoc読めよwww";
sc.add(a);
}
>StreamControllerに値の変更を検知する機能が!?
>あるわけないだろdoc読めよwww
142: デフォルトの名無しさん (ワッチョイ 7f1c-JH9N) [] 2024/06/16(日) 07:03:25.45 ID:IDEikgiG0(3/9) AAS
>>139
なんでおれが君のコードの添削せなあかんねん。
だから、ただの変数に別の値を代入しても検知しないって何度も言ってるやろ。
class A {
String str;
A(this.str);
}
a.str = "あります!";
a.str = "あるわけないだろdoc読めよwww";
main method で StreamCotroller の instance 作成してるけど、この class A は StreamController と全く関係ないから class A の property である str に別の値を代入したところで検知するわけないやろ?
二度とコード書くな。
145: デフォルトの名無しさん (ワッチョイ 9767-1+BE) [] 2024/06/16(日) 08:39:19.15 ID:u7far7aY0(1/2) AAS
>>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でやってるんでしょ?
上下前次1-新書関写板覧索設栞歴
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル
ぬこの手 ぬこTOP 1.019s*