takeWhile method
- booltest(
- Telement
Forwards data events whiletest is successful.
Returns a stream that provides the same events as this streamuntiltest fails for a data event.The returned stream is done when either this stream is done,or when this stream first emits a data event that failstest.
Thetest call is considered failing if it returns a non-true valueor if it throws. If thetest call throws, the error is emitted as thelast event on the returned streams.
Stops listening to this stream after the accepted elements.
Internally the method cancels its subscription after these elements. Thismeans that single-subscription (non-broadcast) streams are closed andcannot be reused after a call to this method.
The returned stream is a broadcast stream if this stream is.For a broadcast stream, the events are only tested from the timethe returned stream is listened to.
Example:
final stream = Stream<int>.periodic(const Duration(seconds: 1), (i) => i) .takeWhile((event) => event < 6);stream.forEach(print); // Outputs events: 0, ..., 5.Implementation
Stream<T> takeWhile(bool test(T element)) { return _TakeWhileStream<T>(this, test);}