disconnect method

  1. @override
Future<ConnectionResponse> disconnect({
  1. Duration? timeout,
})
override

Implementation

@override
Future<ConnectionResponse> disconnect({Duration? timeout}) async {
  if (Platform.isWindows) {
    // Tidy up the printer handle.
    ClosePrinter(hPrinter);
    free(phPrinter!);
    free(pDocName);
    free(pDataType);
    free(dwBytesWritten!);
    free(docInfo!);
    free(szPrinterName);

    this.isConnected = false;
    this.printer.connected = false;
    if (timeout != null) {
      await Future.delayed(timeout, () => null);
    }
    PosPrinterManager.logger.error("disconnect");
    return ConnectionResponse.success;
  } else if (Platform.isAndroid) {
    await usbPrinter.close();
    this.isConnected = false;
    this.printer.connected = false;
    if (timeout != null) {
      await Future.delayed(timeout, () => null);
    }
    return ConnectionResponse.success;
  }
  return ConnectionResponse.timeout;
}