diff --git a/android/build.gradle b/android/build.gradle index 1ce7f8b..650dc01 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -27,6 +27,8 @@ apply plugin: 'kotlin-android' android { compileSdkVersion 31 + namespace 'com.sersoluciones.flutter_pos_printer_platform' // Replace with the actual package name from AndroidManifest.xml + compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 diff --git a/android/src/main/kotlin/com/sersoluciones/flutter_pos_printer_platform/FlutterPosPrinterPlatformPlugin.kt b/android/src/main/kotlin/com/sersoluciones/flutter_pos_printer_platform/FlutterPosPrinterPlatformPlugin.kt index 6ff110b..e54b74a 100644 --- a/android/src/main/kotlin/com/sersoluciones/flutter_pos_printer_platform/FlutterPosPrinterPlatformPlugin.kt +++ b/android/src/main/kotlin/com/sersoluciones/flutter_pos_printer_platform/FlutterPosPrinterPlatformPlugin.kt @@ -200,7 +200,10 @@ class FlutterPosPrinterPlatformPlugin : FlutterPlugin, MethodCallHandler, Plugin adapter = USBPrinterService.getInstance(usbHandler) adapter.init(context) + // Initialize bluetoothService early, to avoid UninitializedPropertyAccessException bluetoothService = BluetoothService.getInstance(bluetoothHandler) + bluetoothService.setHandler(bluetoothHandler) + bluetoothService.setActivity(currentActivity) // In case the activity is already available } override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) { @@ -269,7 +272,9 @@ class FlutterPosPrinterPlatformPlugin : FlutterPlugin, MethodCallHandler, Plugin } } call.method.equals("getList") -> { - bluetoothService.cleanHandlerBtBle() + if(this::bluetoothService.isInitialized){ + bluetoothService.cleanHandlerBtBle() + } getUSBDeviceList(result) } call.method.equals("connectPrinter") -> { @@ -362,10 +367,12 @@ class FlutterPosPrinterPlatformPlugin : FlutterPlugin, MethodCallHandler, Plugin } private fun printBytes(bytes: ArrayList?, result: Result) { - if (bytes == null) return - adapter.setHandler(usbHandler) - adapter.printBytes(bytes) - result.success(true) + if (bytes == null){ + result.success(false) + } else{ + adapter.setHandler(usbHandler) + result.success(adapter.printBytes(bytes)) + } } private fun checkPermissions(): Boolean { diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 9854278..79641d3 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -6,7 +6,7 @@ description: Demonstrates how to use the flutter_pos_printer_platform plugin. publish_to: 'none' # Remove this line if you wish to publish to pub.dev environment: - sdk: '>=2.18.4 <3.3.10' + sdk: '>=3.1.0 <4.0.0' # Dependencies specify other packages that your package needs in order to work. # To automatically upgrade your package dependencies to the latest versions