mohamed yossef
mohamed yossef

Reputation: 25

What is the use of Take method ? Flutter & dart

take-->What role does it play (flutter and Dart)

class Ticker {
  Stream<int> tick({int ticks}) => Stream.periodic(Duration(seconds: 1), (x) {
        return ticks - x - 1;
      }).take(ticks);
}

Upvotes: 2

Views: 564

Answers (1)

blackkara
blackkara

Reputation: 5052

So simply, it just takes items as count of you pass(ticks parameter) from a stream.

// This stream is responsible to do a task for each second 
Stream.periodic(Duration(seconds: 1), (x) {
    return ticks - x - 1;
})

// With take, stream does it's job only `ticks` times
Stream.periodic(Duration(seconds: 1), (x) {
    return ticks - x - 1;
}).take(ticks);

Upvotes: 4

Related Questions