take method

void take(
  1. int count,
  2. void callback(
    1. T value
    )
)

Take only first n value changes

Implementation

void take(int count, void Function(T value) callback) {
  var callCount = 0;
  late VoidCallback listener;

  listener = () {
    if (callCount < count) {
      callCount++;
      callback(value);
      if (callCount >= count) {
        removeListener(listener);
      }
    }
  };

  addListener(listener);
}