我正在用颤振流做一些实验。我有一个生成流的类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这里产生更新的价值?我正在使用StreamBuilderUI 来获取流数据。