Reputation: 191
This is my first Stream class, I have similar class where the interval is 10 seconds and it increment value by 5 called AnotherStream. How can I make sure to pass these to specific widgets in build?
class CounterStream {
final _controller = StreamController<int>();
int _counter = 0;
CounterStream() {
Timer.periodic(const Duration(seconds: 2), (timer) {
_controller.sink.add(_counter++);
});
}
Stream<int> get stream => _controller.stream;
void dispose() => _controller.close();
}
This is the first consumer similar to another following consumer, If only specifier is Consumer how will it know what stream to listen to?
Consumer<int>(
builder: (context, counter, _) {
return Text(
'$counter',
style: const TextStyle(fontSize: 40.0),
);
},
),
Currently both Consumer are listening to AnotherStream & CounterStream is not being used. I have passed both Stream in the MultiProvider & I also tried with different types, StreamProvider & works as expected but not of same data type. What am I doing wrong here?
Upvotes: 0
Views: 28