Skip to content

Instantly share code, notes, and snippets.

@rubgithub
Last active April 15, 2020 20:37
Show Gist options
  • Save rubgithub/2dd3f08445f710da50c34583e30e8f9e to your computer and use it in GitHub Desktop.
Save rubgithub/2dd3f08445f710da50c34583e30e8f9e to your computer and use it in GitHub Desktop.
import 'dart:async';
Stream<int> contStream() async* {
for (var k = 0; k < 10; k++) {
yield k;
}
}
Stream<int> timedCounter() async* {
int i = 0;
while (true) {
await Future.delayed(Duration(seconds: 1));
yield i++;
if (i == 10) break;
}
}
class Bloc {
int _total = 0;
int get total => _total;
final _sc = StreamController<int>();
Stream<int> get stream => _sc.stream;
incrementarTotal(){
_total++;
_sc.add(_total);
}
fechar(){
_sc.close();
}
}
void main() {
var b = Bloc();
print('Bloc');
b.incrementarTotal();
b.stream.listen((data) => print(data));
b.incrementarTotal();
//var k = timedCounter();
//toList Creates and adds all elements of this stream to the list in the order they arrive.
//k.map((data) => print(data)).toList().whenComplete(() => print('done'));
// k.listen(
// (data) => print(data),
// onDone: () => print('Fim'),
// );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment