Answers for "dart stream countdown"

0

dart stream countdown

Stream<int> timedCounter(Duration interval, int count) async* {
  int i = count;
  while (true) {
    await Future.delayed(interval);
    yield --i;
    if (i == 0) break;
  }
}

ttl = 20;
Widget(
  child: StreamBuilder<int>(
      stream: timedCounter(Duration(seconds: 1), ttl),
      initialData: ttl,
      builder: (context, snapshot) => Text(snapshot.data.toString())),
);
Posted by: Guest on July-28-2021

Code answers related to "Dart"

Browse Popular Code Answers by Language