connect method
Connects to a Zebra printer and maintains the connection
address Printer address (MAC address for Bluetooth or IP for Network)
Returns true if connected successfully, false otherwise
Implementation
Future<bool> connect(String address) async {
try {
log('[PrinterManager] connect called for address: $address');
final bool isBluetooth = address.contains(':') && address.length == 17;
if (Platform.isAndroid && isBluetooth) {
final bool granted = await checkAndRequestPermissions();
if (!granted) {
throw Exception("Bluetooth connect permission not granted (BLUETOOTH_CONNECT required on Android 12-17).");
}
}
final result = await _channel.invokeMethod('connect', {'address': address});
log('[PrinterManager] connect result: $result');
return result as bool? ?? false;
} on PlatformException catch (e) {
log('[PrinterManager] connect error: ${e.code} - ${e.message}');
throw Exception("Connection Error (${e.code}): ${e.message}");
}
}