takeFirst method
Take only first n value changes (callback-style listener)
NOTE: Named takeFirst to avoid ambiguity with RxTransformations.take
which returns a computed value instead of registering a callback.
Implementation
void takeFirst(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);
}