我正在用颤振流做一些实验。我有一个生成流的类int
。这是课程:
class CounterRepository {
int _counter = 123;
void increment() {
_counter++;
}
void decrement() {
_counter--;
}
Stream<int> watchCounter() async* {
yield _counter;
}
}
我希望随着 的变化_counter
,watchCounter()
将产生更新的counter
值。当我调用increment()
或decrement()
从 UI 调用时,它的值似乎_counter
正在改变,但watchCounter
不会产生更新的_counter
值。如何在_counter
这里产生更新的价值?我正在使用StreamBuilder
UI 来获取流数据。