kechankrisna / pos_printer_manager

GNU General Public License v3.0
13 stars 53 forks source link

Type cast error in Bluetooth printing(writeBytes) function #18

Open Abdulazeezvp opened 2 years ago

Abdulazeezvp commented 2 years ago

I/flutter ( 3080): capabilities.length is already loaded D/BluetoothSocket( 3080): BT connect calling pid/uid = 3080/10207 W/BluetoothAdapter( 3080): getBluetoothService() called with no BluetoothManagerCallback I/flutter ( 3080): Error : type 'Future<bool?>' is not a subtype of type 'FutureOr' in type cast [log] connection response message : Success

In Bluetooth printer manager, inside write bytes function this casting, line number 87 getting error.

When I changed those line to this, its working good.

 final bool? _isConnected = await bluetooth.isConnected;
        if (_isConnected != null && _isConnected){
      ...

flutter doctor details: Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 2.10.4, on Microsoft Windows [Version 10.0.19043.1586], locale en-IN) [√] Android toolchain - develop for Android devices (Android SDK version 32.0.0) [√] Chrome - develop for the web [!] Visual Studio - develop for Windows (Visual Studio Build Tools 2017 15.9.42) X Visual Studio 2019 or later is required. Download at https://visualstudio.microsoft.com/downloads/. Please install the "Desktop development with C++" workload, including all of its default components [√] Android Studio (version 2020.3) [√] VS Code (version 1.65.2) [√] Connected device (4 available) [√] HTTP Host Availability

htetaunglin commented 2 years ago

I have also this issue.

SouksavathPMS commented 1 year ago

If you see this i have already find a solution

==========================

_startPrinter() async { final content = Demo.getShortReceiptContent(); var bytes = await WebcontentConverter.contentToImage(content: content); var service = ESCPrinterService(bytes); var data = await service.getBytes(paperSize: PaperSize.mm80); if (_manager != null) { print("isConnected ${_manager!.isConnected}"); _manager!.writeBytes(data, isDisconnect: false); } }

on this _startPrint() Function command + click on (writeBytes) inside this _manager!.writeBytes(data, isDisconnect: false);

and then replace the function like this :

===========================

Future writeBytes(List data, {bool isDisconnect: true}) async { try { if (!isConnected) { await connect(); } if (Platform.isAndroid || Platform.isIOS) { final isConnect = await bluetooth.isConnected; if (isConnect ?? false) { 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; } }

====================

Rerun the app and thx me later

Abdulazeezvp commented 1 year ago

I have also this issue, You can use the forked code from my profile.

Jerinji2016 commented 1 year ago

Fixed in MR: https://github.com/kechankrisna/pos_printer_manager/pull/31