add method

  1. @override
void add(
  1. Uint8List data
)
override

Adds raw bytes to the output sink.

The data is sent almost immediately, but if you want to be sure, there is this.allSent that provides future which completes when all added data are sent.

You should use some encoding to send string, for example ascii.encode('Hello!') or utf8.encode('Cześć!).

Might throw StateError("Not connected!") if not connected.

Implementation

@override
void add(Uint8List data) {
  if (!isConnected) {
    throw StateError("Not connected!");
  }

  _chainedFutures = _chainedFutures.then((_) async {
    if (!isConnected) {
      throw StateError("Not connected!");
    }
    await _instance.write(_id, data);
  }).catchError((e) {
    if (kDebugMode) print(e);
    close();
  });
}