getConnectedPrinters method Null safety
- {PrinterDeviceType? type}
override
获取当前已连接的打印机
Implementation
@override
Future<List<PrinterDevice>> getConnectedPrinters(
{PrinterDeviceType? type}) async {
List<PrinterDevice> list = List.empty(growable: true);
switch (type) {
case PrinterDeviceType.usb:
var t = await _getConnectedUsbPrinters();
if (t != null) {
list.addAll(t);
}
break;
case PrinterDeviceType.usbAccessory:
var t = await _getConnectedUsbAccessoryPrinters();
if (t != null) {
list.addAll(t);
}
break;
case PrinterDeviceType.tty:
var t = await _getConnectedTtyPrinters();
if (t != null) {
list.addAll(t);
}
break;
case PrinterDeviceType.tcp:
var t = await _getConnectedTcpPrinters();
if (t != null) {
list.addAll(t);
}
break;
case PrinterDeviceType.bluetooth:
var t = await _getConnectedBluetoothPrinters();
if (t != null) {
list.addAll(t);
}
break;
default:
try {
var t = await _getConnectedUsbPrinters();
if (t != null) {
list.addAll(t);
}
} catch (e) {}
try {
var t = await _getConnectedUsbAccessoryPrinters();
if (t != null) {
list.addAll(t);
}
} catch (e) {}
try {
var t = await _getConnectedTtyPrinters();
if (t != null) {
list.addAll(t);
}
} catch (e) {}
try {
var t = await _getConnectedTcpPrinters();
if (t != null) {
list.addAll(t);
}
} catch (e) {}
try {
var t = await _getConnectedBluetoothPrinters();
if (t != null) {
list.addAll(t);
}
} catch (e) {}
}
return Future.value(list);
}