Movatterモバイル変換


[0]ホーム

URL:


menu
  1. Dart
  2. dart:async
  3. Stream<T>
  4. first property
first
description

first property

Future<T> getfirst

The first element of this stream.

Stops listening to this stream after the first element has been received.

Internally the method cancels its subscription after the first element.This means that single-subscription (non-broadcast) streams are closedand cannot be reused after a call to this getter.

If an error event occurs before the first data event, the returned futureis completed with that error.

If this stream is empty (a done event occurs before the first data event),the returned future completes with an error.

Except for the type of the error, this method is equivalent tothis.elementAt(0).

Implementation

Future<T> get first {  _Future<T> future = _Future<T>();  StreamSubscription<T> subscription = this.listen(    null,    onError: future._completeError,    onDone: () {      var stack = StackTrace.empty;      var error = IterableElementError.noElement();      _trySetStackTrace(error, stack);      _completeWithErrorCallback(future, error, stack);    },    cancelOnError: true,  );  subscription.onData((T value) {    _cancelAndValue(subscription, future, value);  });  return future;}
  1. Dart
  2. dart:async
  3. Stream<T>
  4. first property
Stream class

[8]ページ先頭

©2009-2025 Movatter.jp