every method
- booltest(
- Telement
Checks whethertest accepts all elements provided by this stream.
Callstest on each element of this stream.If the call returnsfalse, the returned future is completed withfalseand processing stops.
If this stream ends without finding an element thattest rejects,the returned future is completed withtrue.
If this stream emits an error, or if the call totest throws,the returned future is completed with that error,and processing stops.
Example:
final result = await Stream.periodic(const Duration(seconds: 1), (count) => count) .take(15) .every((x) => x <= 5);print(result); // falseImplementation
Future<bool> every(bool test(T element)) { _Future<bool> future = _Future<bool>(); StreamSubscription<T> subscription = this.listen( null, onError: future._completeError, onDone: () { future._complete(true); }, cancelOnError: true, ); subscription.onData((T element) { _runUserCode(() => test(element), (bool isMatch) { if (!isMatch) { _cancelAndValue(subscription, future, false); } }, _cancelAndErrorClosure(subscription, future)); }); return future;}