Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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") -> {
Expand Down Expand Up @@ -362,10 +367,12 @@ class FlutterPosPrinterPlatformPlugin : FlutterPlugin, MethodCallHandler, Plugin
}

private fun printBytes(bytes: ArrayList<Int>?, 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 {
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down