andriyoganp / blue_print_pos

Helper to use bluetooth print in Android and iOS
Apache License 2.0
34 stars 77 forks source link

not work with printer MPT-II #74

Open YouSour opened 1 year ago

YouSour commented 1 year ago

hi, i just text example code it look like it doesn't with printer MPT-II , it got an error below Screen Shot 2022-11-01 at 12 05 57 PM

ankush-ppie commented 1 year ago

Hi @YouSour

I also face same issue with iOS. Please use this library or add code in your forked library.

lib/blue_print_pos.dart

Remove this code:

final flutter_blue.BluetoothCharacteristic characteristic =
            bluetoothService.characteristics.firstWhere(
          (flutter_blue.BluetoothCharacteristic bluetoothCharacteristic) =>
              bluetoothCharacteristic.properties.write,
        );
await characteristic.write(byteBuffer, withoutResponse: true);

Add this code:

final List<flutter_blue.BluetoothCharacteristic>
            writableCharacteristics = bluetoothService.characteristics
                .where((flutter_blue.BluetoothCharacteristic
                        bluetoothCharacteristic) =>
                    bluetoothCharacteristic.properties.write == true)
                .toList();
        if (writableCharacteristics.isNotEmpty) {
          await writableCharacteristics[0]
              .write(byteBuffer, withoutResponse: true);
        } else {
          final List<flutter_blue.BluetoothCharacteristic>
              writableWithoutResponseCharacteristics = bluetoothService
                  .characteristics
                  .where((flutter_blue.BluetoothCharacteristic
                          bluetoothCharacteristic) =>
                      bluetoothCharacteristic.properties.writeWithoutResponse ==
                      true)
                  .toList();
          if (writableWithoutResponseCharacteristics.isNotEmpty) {
            await writableWithoutResponseCharacteristics[0]
                .write(byteBuffer, withoutResponse: true);
          }
        }

Reference: Screenshot 2022-12-25 at 9 03 59 AM

YouSour commented 1 year ago

@ankush-ppie ok, i'll test it later