onDataReceived method

void onDataReceived(
  1. List<int> data
)

Called when data is received from the download characteristic.

Accumulates data and emits progress. Detects completion when an empty array is received (per BLE spec), but only after we've received at least one block of actual data.

Implementation

void onDataReceived(List<int> data) {
  if (!isActive) return;

  // Empty array signals fetch completion per BLE spec,
  // but only if we've already received some data.
  // This ignores the initial empty value from lastValueStream.
  if (data.isEmpty) {
    if (_hasReceivedData) {
      _completeFetch();
    }
    return;
  }

  _hasReceivedData = true;
  _buffer.add(data);
  final received = _buffer.length;

  emitProgress(FetchProgress.inProgress(
    receivedBytes: received,
  ));
}