printBytes method

Future<void> printBytes({
  1. required Uint8List bytes,
  2. void progress(
    1. int total,
    2. int progress
    )?,
})

Implementation

Future<void> printBytes({
  required Uint8List bytes,
  void Function(int total, int progress)? progress,
}) async {
  final completer = Completer<bool>();
  StreamSubscription? listener;
  listener = _plugin._printingProgress.stream.listen((event) {
    final int t = event['total'];
    final int p = event['progress'];
    if (progress != null) {
      progress(t, p);
    }

    if (t == p) {
      listener?.cancel();
      if (!completer.isCompleted) {
        completer.complete(true);
      }
    }
  });

  await _plugin._channel.invokeMethod(
    'print',
    bytes,
  );

  await completer.future;
}