writeBytes method

  1. @override
Future<ConnectionResponse> writeBytes(
  1. List<int> data, {
  2. bool isDisconnect = true,
})
override

writeBytes let you write raw list int data into socket

Implementation

@override
Future<ConnectionResponse> writeBytes(List<int> data,
    {bool isDisconnect: true}) async {
  try {
    if (!isConnected) {
      await connect();
    }
    if (Platform.isAndroid || Platform.isIOS) {
      if ((await (bluetooth.isConnected as FutureOr<bool>))) {
        Uint8List message = Uint8List.fromList(data);
        PosPrinterManager.logger.warning("message.length ${message.length}");
        await bluetooth.writeBytes(message);
        if (isDisconnect) {
          await disconnect();
        }
        return ConnectionResponse.success;
      }
      return ConnectionResponse.printerNotConnected;
    }
    //  else if (Platform.isIOS) {
    //   // var services = (await fbdevice.discoverServices());
    //   // var service = services.firstWhere((e) => e.isPrimary);
    //   // var charactor =
    //   //     service.characteristics.firstWhere((e) => e.properties.write);
    //   // await charactor?.write(data, withoutResponse: true);
    //   return ConnectionResponse.success;
    // }
    return ConnectionResponse.unsupport;
  } catch (e) {
    print("Error : $e");
    return ConnectionResponse.unknown;
  }
}