connect method
connect let you connect to a bluetooth printer
Implementation
Future<ConnectionResponse> connect(
{Duration? timeout: const Duration(seconds: 5)}) async {
try {
// if (Platform.isIOS) {
// fbdevice = fblue.BluetoothDevice.fromProto(proto.BluetoothDevice(
// name: printer.name,
// remoteId: printer.address,
// type: proto.BluetoothDevice_Type.valueOf(printer.type)));
// var connected = await flutterBlue.connectedDevices;
// var index = connected?.indexWhere((e) => e.id == fbdevice.id);
// if (index < 0) await fbdevice.connect();
// } else
if (Platform.isAndroid || Platform.isIOS) {
var device = themal.BluetoothDevice(printer.name, printer.address);
await bluetooth.connect(device);
}
this.isConnected = true;
this.printer.connected = true;
return Future<ConnectionResponse>.value(ConnectionResponse.success);
} catch (e) {
this.isConnected = false;
this.printer.connected = false;
return Future<ConnectionResponse>.value(ConnectionResponse.timeout);
}
}