diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..fee88da --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "example", + "cwd": "example", + "request": "launch", + "type": "dart" + }, + { + "name": "example (profile mode)", + "cwd": "example", + "request": "launch", + "type": "dart", + "flutterMode": "profile" + }, + { + "name": "example (release mode)", + "cwd": "example", + "request": "launch", + "type": "dart", + "flutterMode": "release" + } + ] +} diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 4ce72ee..f22db2c 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,5 +1,5 @@ + > diff --git a/android/src/main/kotlin/com/emddigital/barcode_kit/BarcodeKitPlugin.kt b/android/src/main/kotlin/com/emddigital/mtrust_barcode_kit/BarcodeKitPlugin.kt similarity index 97% rename from android/src/main/kotlin/com/emddigital/barcode_kit/BarcodeKitPlugin.kt rename to android/src/main/kotlin/com/emddigital/mtrust_barcode_kit/BarcodeKitPlugin.kt index e2ad5ca..6320b28 100644 --- a/android/src/main/kotlin/com/emddigital/barcode_kit/BarcodeKitPlugin.kt +++ b/android/src/main/kotlin/com/emddigital/mtrust_barcode_kit/BarcodeKitPlugin.kt @@ -1,4 +1,4 @@ -package com.emddigital.barcode_kit +package com.emddigital.mtrust_barcode_kit import BarcodeFormat @@ -44,13 +44,13 @@ val barcodeFormatMap = hashMapOf( BarcodeFormat.CODE39 to Barcode.FORMAT_CODE_39, BarcodeFormat.CODE93 to Barcode.FORMAT_CODE_93, BarcodeFormat.CODE128 to Barcode.FORMAT_CODE_128, - BarcodeFormat.DATAMATRIX to Barcode.FORMAT_DATA_MATRIX, + BarcodeFormat.DATA_MATRIX to Barcode.FORMAT_DATA_MATRIX, BarcodeFormat.EAN8 to Barcode.FORMAT_EAN_8, BarcodeFormat.EAN13 to Barcode.FORMAT_EAN_13, BarcodeFormat.PDF417 to Barcode.FORMAT_PDF417, - BarcodeFormat.QRCODE to Barcode.FORMAT_QR_CODE, - BarcodeFormat.UPCA to Barcode.FORMAT_UPC_A, - BarcodeFormat.UPCE to Barcode.FORMAT_UPC_E, + BarcodeFormat.QR_CODE to Barcode.FORMAT_QR_CODE, + BarcodeFormat.UPC_A to Barcode.FORMAT_UPC_A, + BarcodeFormat.UPC_E to Barcode.FORMAT_UPC_E, BarcodeFormat.ITF to Barcode.FORMAT_ITF ) diff --git a/android/src/main/kotlin/com/emddigital/barcode_kit/pigeon/Pigeon.kt b/android/src/main/kotlin/com/emddigital/mtrust_barcode_kit/pigeon/Pigeon.kt similarity index 58% rename from android/src/main/kotlin/com/emddigital/barcode_kit/pigeon/Pigeon.kt rename to android/src/main/kotlin/com/emddigital/mtrust_barcode_kit/pigeon/Pigeon.kt index 50338d0..53f62b8 100644 --- a/android/src/main/kotlin/com/emddigital/barcode_kit/pigeon/Pigeon.kt +++ b/android/src/main/kotlin/com/emddigital/mtrust_barcode_kit/pigeon/Pigeon.kt @@ -1,11 +1,14 @@ -// Autogenerated from Pigeon (v10.1.6), do not edit directly. +// Autogenerated from Pigeon (v24.1.0), do not edit directly. // See also: https://pub.dev/packages/pigeon +@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass") import android.util.Log import io.flutter.plugin.common.BasicMessageChannel import io.flutter.plugin.common.BinaryMessenger +import io.flutter.plugin.common.EventChannel import io.flutter.plugin.common.MessageCodec +import io.flutter.plugin.common.StandardMethodCodec import io.flutter.plugin.common.StandardMessageCodec import java.io.ByteArrayOutputStream import java.nio.ByteBuffer @@ -15,14 +18,14 @@ private fun wrapResult(result: Any?): List { } private fun wrapError(exception: Throwable): List { - if (exception is FlutterError) { - return listOf( + return if (exception is FlutterError) { + listOf( exception.code, exception.message, exception.details ) } else { - return listOf( + listOf( exception.javaClass.simpleName, exception.toString(), "Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception) @@ -30,6 +33,9 @@ private fun wrapError(exception: Throwable): List { } } +private fun createConnectionError(channelName: String): FlutterError { + return FlutterError("channel-error", "Unable to establish connection on channel: '$channelName'.", "")} + /** * Error class for passing custom error details to Flutter via a thrown PlatformException. * @property code The error code. @@ -48,13 +54,13 @@ enum class BarcodeFormat(val raw: Int) { CODE39(2), CODE93(3), CODE128(4), - DATAMATRIX(5), + DATA_MATRIX(5), EAN8(6), EAN13(7), PDF417(8), - QRCODE(9), - UPCA(10), - UPCE(11), + QR_CODE(9), + UPC_A(10), + UPC_E(11), ITF(12); companion object { @@ -83,20 +89,19 @@ data class CameraOpenResponse ( val height: Long? = null, val width: Long? = null, val textureId: String? = null - -) { +) + { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): CameraOpenResponse { - val supportsFlash = list[0] as Boolean? - val height = list[1].let { if (it is Int) it.toLong() else it as Long? } - val width = list[2].let { if (it is Int) it.toLong() else it as Long? } - val textureId = list[3] as String? + fun fromList(pigeonVar_list: List): CameraOpenResponse { + val supportsFlash = pigeonVar_list[0] as Boolean? + val height = pigeonVar_list[1] as Long? + val width = pigeonVar_list[2] as Long? + val textureId = pigeonVar_list[3] as String? return CameraOpenResponse(supportsFlash, height, width, textureId) } } fun toList(): List { - return listOf( + return listOf( supportsFlash, height, width, @@ -111,25 +116,22 @@ data class DetectedBarcode ( val cornerPoints: List? = null, val format: BarcodeFormat? = null, val textValue: String? = null - -) { +) + { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): DetectedBarcode { - val rawValue = list[0] as String? - val cornerPoints = list[1] as List? - val format: BarcodeFormat? = (list[2] as Int?)?.let { - BarcodeFormat.ofRaw(it) - } - val textValue = list[3] as String? + fun fromList(pigeonVar_list: List): DetectedBarcode { + val rawValue = pigeonVar_list[0] as String? + val cornerPoints = pigeonVar_list[1] as List? + val format = pigeonVar_list[2] as BarcodeFormat? + val textValue = pigeonVar_list[3] as String? return DetectedBarcode(rawValue, cornerPoints, format, textValue) } } fun toList(): List { - return listOf( + return listOf( rawValue, cornerPoints, - format?.raw, + format, textValue, ) } @@ -139,40 +141,73 @@ data class DetectedBarcode ( data class CornerPoint ( val x: Double, val y: Double - -) { +) + { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): CornerPoint { - val x = list[0] as Double - val y = list[1] as Double + fun fromList(pigeonVar_list: List): CornerPoint { + val x = pigeonVar_list[0] as Double + val y = pigeonVar_list[1] as Double return CornerPoint(x, y) } } fun toList(): List { - return listOf( + return listOf( x, y, ) } } - -@Suppress("UNCHECKED_CAST") -private object BarcodeKitHostApiCodec : StandardMessageCodec() { +private open class PigeonPigeonCodec : StandardMessageCodec() { override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { return when (type) { - 128.toByte() -> { + 129.toByte() -> { + return (readValue(buffer) as Long?)?.let { + BarcodeFormat.ofRaw(it.toInt()) + } + } + 130.toByte() -> { + return (readValue(buffer) as Long?)?.let { + CameraLensDirection.ofRaw(it.toInt()) + } + } + 131.toByte() -> { return (readValue(buffer) as? List)?.let { CameraOpenResponse.fromList(it) } } + 132.toByte() -> { + return (readValue(buffer) as? List)?.let { + DetectedBarcode.fromList(it) + } + } + 133.toByte() -> { + return (readValue(buffer) as? List)?.let { + CornerPoint.fromList(it) + } + } else -> super.readValueOfType(type, buffer) } } override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { when (value) { + is BarcodeFormat -> { + stream.write(129) + writeValue(stream, value.raw) + } + is CameraLensDirection -> { + stream.write(130) + writeValue(stream, value.raw) + } is CameraOpenResponse -> { - stream.write(128) + stream.write(131) + writeValue(stream, value.toList()) + } + is DetectedBarcode -> { + stream.write(132) + writeValue(stream, value.toList()) + } + is CornerPoint -> { + stream.write(133) writeValue(stream, value.toList()) } else -> super.writeValue(stream, value) @@ -180,6 +215,7 @@ private object BarcodeKitHostApiCodec : StandardMessageCodec() { } } + /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ interface BarcodeKitHostApi { fun openCamera(direction: CameraLensDirection, formats: List, callback: (Result) -> Unit) @@ -192,17 +228,18 @@ interface BarcodeKitHostApi { companion object { /** The codec used by BarcodeKitHostApi. */ val codec: MessageCodec by lazy { - BarcodeKitHostApiCodec + PigeonPigeonCodec() } /** Sets up an instance of `BarcodeKitHostApi` to handle messages through the `binaryMessenger`. */ - @Suppress("UNCHECKED_CAST") - fun setUp(binaryMessenger: BinaryMessenger, api: BarcodeKitHostApi?) { + @JvmOverloads + fun setUp(binaryMessenger: BinaryMessenger, api: BarcodeKitHostApi?, messageChannelSuffix: String = "") { + val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.barcode_kit.BarcodeKitHostApi.openCamera", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitHostApi.openCamera$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List - val directionArg = CameraLensDirection.ofRaw(args[0] as Int)!! + val directionArg = args[0] as CameraLensDirection val formatsArg = args[1] as List api.openCamera(directionArg, formatsArg) { result: Result -> val error = result.exceptionOrNull() @@ -219,17 +256,16 @@ interface BarcodeKitHostApi { } } run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.barcode_kit.BarcodeKitHostApi.setOCREnabled", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitHostApi.setOCREnabled$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List val enabledArg = args[0] as Boolean - var wrapped: List - try { + val wrapped: List = try { api.setOCREnabled(enabledArg) - wrapped = listOf(null) + listOf(null) } catch (exception: Throwable) { - wrapped = wrapError(exception) + wrapError(exception) } reply.reply(wrapped) } @@ -238,15 +274,14 @@ interface BarcodeKitHostApi { } } run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.barcode_kit.BarcodeKitHostApi.closeCamera", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitHostApi.closeCamera$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { _, reply -> - var wrapped: List - try { + val wrapped: List = try { api.closeCamera() - wrapped = listOf(null) + listOf(null) } catch (exception: Throwable) { - wrapped = wrapError(exception) + wrapError(exception) } reply.reply(wrapped) } @@ -255,15 +290,14 @@ interface BarcodeKitHostApi { } } run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.barcode_kit.BarcodeKitHostApi.pauseCamera", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitHostApi.pauseCamera$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { _, reply -> - var wrapped: List - try { + val wrapped: List = try { api.pauseCamera() - wrapped = listOf(null) + listOf(null) } catch (exception: Throwable) { - wrapped = wrapError(exception) + wrapError(exception) } reply.reply(wrapped) } @@ -272,15 +306,14 @@ interface BarcodeKitHostApi { } } run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.barcode_kit.BarcodeKitHostApi.resumeCamera", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitHostApi.resumeCamera$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { _, reply -> - var wrapped: List - try { + val wrapped: List = try { api.resumeCamera() - wrapped = listOf(null) + listOf(null) } catch (exception: Throwable) { - wrapped = wrapError(exception) + wrapError(exception) } reply.reply(wrapped) } @@ -289,17 +322,16 @@ interface BarcodeKitHostApi { } } run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.barcode_kit.BarcodeKitHostApi.setTorch", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitHostApi.setTorch$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List val enabledArg = args[0] as Boolean - var wrapped: List - try { + val wrapped: List = try { api.setTorch(enabledArg) - wrapped = listOf(null) + listOf(null) } catch (exception: Throwable) { - wrapped = wrapError(exception) + wrapError(exception) } reply.reply(wrapped) } @@ -310,66 +342,66 @@ interface BarcodeKitHostApi { } } } -@Suppress("UNCHECKED_CAST") -private object BarcodeKitFlutterApiCodec : StandardMessageCodec() { - override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { - return when (type) { - 128.toByte() -> { - return (readValue(buffer) as? List)?.let { - CornerPoint.fromList(it) - } - } - 129.toByte() -> { - return (readValue(buffer) as? List)?.let { - DetectedBarcode.fromList(it) - } - } - else -> super.readValueOfType(type, buffer) - } - } - override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { - when (value) { - is CornerPoint -> { - stream.write(128) - writeValue(stream, value.toList()) - } - is DetectedBarcode -> { - stream.write(129) - writeValue(stream, value.toList()) - } - else -> super.writeValue(stream, value) - } - } -} - /** Generated class from Pigeon that represents Flutter messages that can be called from Kotlin. */ -@Suppress("UNCHECKED_CAST") -class BarcodeKitFlutterApi(private val binaryMessenger: BinaryMessenger) { +class BarcodeKitFlutterApi(private val binaryMessenger: BinaryMessenger, private val messageChannelSuffix: String = "") { companion object { /** The codec used by BarcodeKitFlutterApi. */ val codec: MessageCodec by lazy { - BarcodeKitFlutterApiCodec + PigeonPigeonCodec() } } /** Caleld from the host when a barcode is detected. */ - fun onBarcodeScanned(barcodeArg: DetectedBarcode, callback: () -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.barcode_kit.BarcodeKitFlutterApi.onBarcodeScanned", codec) + fun onBarcodeScanned(barcodeArg: DetectedBarcode, callback: (Result) -> Unit) +{ + val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" + val channelName = "dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitFlutterApi.onBarcodeScanned$separatedMessageChannelSuffix" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(barcodeArg)) { - callback() + if (it is List<*>) { + if (it.size > 1) { + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } } } /** Called from the host when text is detected. */ - fun onTextDetected(textArg: String, callback: () -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.barcode_kit.BarcodeKitFlutterApi.onTextDetected", codec) + fun onTextDetected(textArg: String, callback: (Result) -> Unit) +{ + val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" + val channelName = "dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitFlutterApi.onTextDetected$separatedMessageChannelSuffix" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(textArg)) { - callback() + if (it is List<*>) { + if (it.size > 1) { + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } } } /** Called from the host when the torch state changes. */ - fun onTorchStateChanged(enabledArg: Boolean, callback: () -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.barcode_kit.BarcodeKitFlutterApi.onTorchStateChanged", codec) + fun onTorchStateChanged(enabledArg: Boolean, callback: (Result) -> Unit) +{ + val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" + val channelName = "dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitFlutterApi.onTorchStateChanged$separatedMessageChannelSuffix" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(enabledArg)) { - callback() + if (it is List<*>) { + if (it.size > 1) { + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } } } } diff --git a/example/.gitignore b/example/.gitignore index 24476c5..6c31954 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -5,9 +5,11 @@ *.swp .DS_Store .atom/ +.build/ .buildlog/ .history .svn/ +.swiftpm/ migrate_working_dir/ # IntelliJ related diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 92e45da..cba7ed1 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -28,6 +28,8 @@ android { compileSdkVersion flutter.compileSdkVersion ndkVersion flutter.ndkVersion + namespace "com.emddigital.barcode_kit_example" + compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 diff --git a/example/android/build.gradle b/example/android/build.gradle index 8f31e8c..3c29d0d 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -3,6 +3,17 @@ allprojects { google() mavenCentral() } + subprojects { + afterEvaluate { project -> + if (project.hasProperty('android')) { + project.android { + if (namespace == null) { + namespace project.group + } + } + } + } + } } rootProject.buildDir = '../build' diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 05e070b..f5a379c 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -18,7 +18,7 @@ pluginManagement { plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" - id "com.android.application" version "7.3.0" apply false + id "com.android.application" version "8.1.0" apply false id "org.jetbrains.kotlin.android" version "1.8.0" apply false } diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 65fec55..ab48fa2 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1,34 +1,34 @@ PODS: - - barcode_kit (0.0.1): - - Flutter - Flutter (1.0.0) + - mtrust_barcode_kit (0.0.1): + - Flutter - native_device_orientation (0.0.1): - Flutter - permission_handler_apple (9.3.0): - Flutter DEPENDENCIES: - - barcode_kit (from `.symlinks/plugins/barcode_kit/ios`) - Flutter (from `Flutter`) + - mtrust_barcode_kit (from `.symlinks/plugins/mtrust_barcode_kit/ios`) - native_device_orientation (from `.symlinks/plugins/native_device_orientation/ios`) - permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`) EXTERNAL SOURCES: - barcode_kit: - :path: ".symlinks/plugins/barcode_kit/ios" Flutter: :path: Flutter + mtrust_barcode_kit: + :path: ".symlinks/plugins/mtrust_barcode_kit/ios" native_device_orientation: :path: ".symlinks/plugins/native_device_orientation/ios" permission_handler_apple: :path: ".symlinks/plugins/permission_handler_apple/ios" SPEC CHECKSUMS: - barcode_kit: fa9db39e48737deac1e76dbca206f41e60656d4a Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 + mtrust_barcode_kit: 666829c671d5258fe6d9bf7ea5f7a80501d28994 native_device_orientation: 348b10c346a60ebbc62fb235a4fdb5d1b61a8f55 permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2 PODFILE CHECKSUM: af58d951dbef8da019280072eabcbd9dcc50cf6f -COCOAPODS: 1.15.2 +COCOAPODS: 1.16.2 diff --git a/example/pubspec.lock b/example/pubspec.lock index edeb047..b5eee36 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,18 +5,18 @@ packages: dependency: transitive description: name: archive - sha256: cb6a278ef2dbb298455e1a713bda08524a175630ec643a242c399c932a0a1f7d + sha256: "6199c74e3db4fbfbd04f66d739e72fe11c8a8957d5f219f1f4482dbde6420b5a" url: "https://pub.dev" source: hosted - version: "3.6.1" + version: "4.0.2" args: dependency: transitive description: name: args - sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a" + sha256: bf9f5caeea8d8fe6721a9c358dd8a5c1947b27f1cfaa18b39c301273594919e6 url: "https://pub.dev" source: hosted - version: "2.5.0" + version: "2.6.0" async: dependency: transitive description: @@ -53,18 +53,18 @@ packages: dependency: transitive description: name: collection - sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf url: "https://pub.dev" source: hosted - version: "1.18.0" + version: "1.19.0" crypto: dependency: transitive description: name: crypto - sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab + sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855" url: "https://pub.dev" source: hosted - version: "3.0.3" + version: "3.0.6" cupertino_icons: dependency: "direct main" description: @@ -77,10 +77,10 @@ packages: dependency: "direct main" description: name: equatable - sha256: c2b87cb7756efdf69892005af546c56c0b5037f54d2a88269b4f347a505e3ca2 + sha256: "567c64b3cb4cf82397aac55f4f0cbd3ca20d77c6c03bedbc4ceaddc08904aef7" url: "https://pub.dev" source: hosted - version: "2.0.5" + version: "2.0.7" fake_async: dependency: transitive description: @@ -89,6 +89,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.1" + ffi: + dependency: transitive + description: + name: ffi + sha256: "16ed7b077ef01ad6170a3d0c57caa4a112a38d7a2ed5602e0aca9ca6f3d98da6" + url: "https://pub.dev" + source: hosted + version: "2.1.3" flutter: dependency: "direct main" description: flutter @@ -98,10 +106,10 @@ packages: dependency: "direct main" description: name: flutter_animate - sha256: "7c8a6594a9252dad30cc2ef16e33270b6248c4dedc3b3d06c86c4f3f4dc05ae5" + sha256: "7befe2d3252728afb77aecaaea1dec88a89d35b9b1d2eea6d04479e8af9117b5" url: "https://pub.dev" source: hosted - version: "4.5.0" + version: "4.5.2" flutter_lints: dependency: "direct dev" description: @@ -122,10 +130,10 @@ packages: dependency: transitive description: name: flutter_shaders - sha256: "02750b545c01ff4d8e9bbe8f27a7731aa3778402506c67daa1de7f5fc3f4befe" + sha256: "34794acadd8275d971e02df03afee3dee0f98dbfb8c4837082ad0034f612a3e2" url: "https://pub.dev" source: hosted - version: "0.1.2" + version: "0.1.3" flutter_test: dependency: "direct dev" description: flutter @@ -148,26 +156,26 @@ packages: dependency: transitive description: name: image - sha256: "2237616a36c0d69aef7549ab439b833fb7f9fb9fc861af2cc9ac3eedddd69ca8" + sha256: "8346ad4b5173924b5ddddab782fc7d8a6300178c8b1dc427775405a01701c4a6" url: "https://pub.dev" source: hosted - version: "4.2.0" + version: "4.5.2" leak_tracker: dependency: transitive description: name: leak_tracker - sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" + sha256: "7bb2830ebd849694d1ec25bf1f44582d6ac531a57a365a803a6034ff751d2d06" url: "https://pub.dev" source: hosted - version: "10.0.5" + version: "10.0.7" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" + sha256: "9491a714cca3667b60b5c420da8217e6de0d1ba7a5ec322fab01758f6998f379" url: "https://pub.dev" source: hosted - version: "3.0.5" + version: "3.0.8" leak_tracker_testing: dependency: transitive description: @@ -243,10 +251,10 @@ packages: dependency: transitive description: name: permission_handler_android - sha256: "8bb852cd759488893805c3161d0b2b5db55db52f773dbb014420b304055ba2c5" + sha256: "71bbecfee799e65aff7c744761a57e817e73b738fedf62ab7afd5593da21f9f1" url: "https://pub.dev" source: hosted - version: "12.0.6" + version: "12.0.13" permission_handler_apple: dependency: transitive description: @@ -259,18 +267,18 @@ packages: dependency: transitive description: name: permission_handler_html - sha256: "54bf176b90f6eddd4ece307e2c06cf977fb3973719c35a93b85cc7093eb6070d" + sha256: "38f000e83355abb3392140f6bc3030660cfaef189e1f87824facb76300b4ff24" url: "https://pub.dev" source: hosted - version: "0.1.1" + version: "0.1.3+5" permission_handler_platform_interface: dependency: transitive description: name: permission_handler_platform_interface - sha256: "48d4fcf201a1dad93ee869ab0d4101d084f49136ec82a8a06ed9cfeacab9fd20" + sha256: e9c8eadee926c4532d0305dff94b85bf961f16759c3af791486613152af4b4f9 url: "https://pub.dev" source: hosted - version: "4.2.1" + version: "4.2.3" permission_handler_windows: dependency: transitive description: @@ -295,11 +303,19 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.8" + posix: + dependency: transitive + description: + name: posix + sha256: a0117dc2167805aa9125b82eee515cc891819bac2f538c83646d355b16f58b9a + url: "https://pub.dev" + source: hosted + version: "6.0.1" sky_engine: dependency: transitive description: flutter source: sdk - version: "0.0.99" + version: "0.0.0" source_span: dependency: transitive description: @@ -312,10 +328,10 @@ packages: dependency: transitive description: name: stack_trace - sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + sha256: "9f47fd3630d76be3ab26f0ee06d213679aa425996925ff3feffdec504931c377" url: "https://pub.dev" source: hosted - version: "1.11.1" + version: "1.12.0" stream_channel: dependency: transitive description: @@ -328,10 +344,10 @@ packages: dependency: transitive description: name: string_scanner - sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3" url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.3.0" term_glyph: dependency: transitive description: @@ -344,18 +360,18 @@ packages: dependency: transitive description: name: test_api - sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" + sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c" url: "https://pub.dev" source: hosted - version: "0.7.2" + version: "0.7.3" typed_data: dependency: transitive description: name: typed_data - sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006 url: "https://pub.dev" source: hosted - version: "1.3.2" + version: "1.4.0" universal_io: dependency: transitive description: @@ -376,10 +392,18 @@ packages: dependency: transitive description: name: vm_service - sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" + sha256: f6be3ed8bd01289b34d679c2b62226f63c0e69f9fd2e50a6b3c1c729a961041b + url: "https://pub.dev" + source: hosted + version: "14.3.0" + web: + dependency: transitive + description: + name: web + sha256: cd3543bd5798f6ad290ea73d210f423502e71900302dde696f8bff84bf89a1cb url: "https://pub.dev" source: hosted - version: "14.2.5" + version: "1.1.0" xml: dependency: transitive description: @@ -392,10 +416,10 @@ packages: dependency: transitive description: name: yaml - sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" + sha256: b9da305ac7c39faa3f030eccd175340f968459dae4af175130b3fc47e40d76ce url: "https://pub.dev" source: hosted - version: "3.1.2" + version: "3.1.3" sdks: - dart: ">=3.3.1 <4.0.0" + dart: ">=3.5.0 <4.0.0" flutter: ">=3.18.0-18.0.pre.54" diff --git a/generate.sh b/generate.sh index 9a019e5..2e9a97e 100755 --- a/generate.sh +++ b/generate.sh @@ -1,6 +1,6 @@ -flutter pub run pigeon \ +dart run pigeon \ --input pigeons/barcode_kit_pigeon.dart \ --dart_out lib/src/pigeon.dart \ --experimental_swift_out ios/Classes/Pigeon.swift \ - --experimental_kotlin_out android/src/main/kotlin/com/emddigital/barcode_kit/pigeon/Pigeon.kt \ - --java_package "com.emddigital.barcode_kit.pigeon" \ \ No newline at end of file + --experimental_kotlin_out android/src/main/kotlin/com/emddigital/mtrust_barcode_kit/pigeon/Pigeon.kt \ + --java_package "com.emddigital.mtrust_barcode_kit.pigeon" \ \ No newline at end of file diff --git a/ios/Classes/BarcodeKitPlugin.m b/ios/Classes/BarcodeKitPlugin.m index b21b967..b0ef5a0 100644 --- a/ios/Classes/BarcodeKitPlugin.m +++ b/ios/Classes/BarcodeKitPlugin.m @@ -1,11 +1,11 @@ #import "BarcodeKitPlugin.h" -#if __has_include() -#import +#if __has_include() +#import #else // Support project import fallback if the generated compatibility header // is not copied when this plugin is created as a library. // https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816 -#import "barcode_kit-Swift.h" +#import "mtrust_barcode_kit-Swift.h" #endif @implementation BarcodeKitPlugin diff --git a/ios/Classes/Pigeon.swift b/ios/Classes/Pigeon.swift index e772ee9..b121626 100644 --- a/ios/Classes/Pigeon.swift +++ b/ios/Classes/Pigeon.swift @@ -1,34 +1,68 @@ -// Autogenerated from Pigeon (v10.1.6), do not edit directly. +// Autogenerated from Pigeon (v24.1.0), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation + #if os(iOS) -import Flutter + import Flutter #elseif os(macOS) -import FlutterMacOS + import FlutterMacOS #else -#error("Unsupported platform.") + #error("Unsupported platform.") #endif +/// Error class for passing custom error details to Dart side. +final class PigeonError: Error { + let code: String + let message: String? + let details: Sendable? + + init(code: String, message: String?, details: Sendable?) { + self.code = code + self.message = message + self.details = details + } + + var localizedDescription: String { + return + "PigeonError(code: \(code), message: \(message ?? ""), details: \(details ?? "")" + } +} + private func wrapResult(_ result: Any?) -> [Any?] { return [result] } private func wrapError(_ error: Any) -> [Any?] { + if let pigeonError = error as? PigeonError { + return [ + pigeonError.code, + pigeonError.message, + pigeonError.details, + ] + } if let flutterError = error as? FlutterError { return [ flutterError.code, flutterError.message, - flutterError.details + flutterError.details, ] } return [ "\(error)", "\(type(of: error))", - "Stacktrace: \(Thread.callStackSymbols)" + "Stacktrace: \(Thread.callStackSymbols)", ] } +private func createConnectionError(withChannelName channelName: String) -> PigeonError { + return PigeonError(code: "channel-error", message: "Unable to establish connection on channel: '\(channelName)'.", details: "") +} + +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + private func nilOrValue(_ value: Any?) -> T? { if value is NSNull { return nil } return value as! T? @@ -64,11 +98,13 @@ struct CameraOpenResponse { var width: Int64? = nil var textureId: String? = nil - static func fromList(_ list: [Any?]) -> CameraOpenResponse? { - let supportsFlash: Bool? = nilOrValue(list[0]) - let height: Int64? = list[1] is NSNull ? nil : (list[1] is Int64? ? list[1] as! Int64? : Int64(list[1] as! Int32)) - let width: Int64? = list[2] is NSNull ? nil : (list[2] is Int64? ? list[2] as! Int64? : Int64(list[2] as! Int32)) - let textureId: String? = nilOrValue(list[3]) + + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> CameraOpenResponse? { + let supportsFlash: Bool? = nilOrValue(pigeonVar_list[0]) + let height: Int64? = nilOrValue(pigeonVar_list[1]) + let width: Int64? = nilOrValue(pigeonVar_list[2]) + let textureId: String? = nilOrValue(pigeonVar_list[3]) return CameraOpenResponse( supportsFlash: supportsFlash, @@ -94,15 +130,13 @@ struct DetectedBarcode { var format: BarcodeFormat? = nil var textValue: String? = nil - static func fromList(_ list: [Any?]) -> DetectedBarcode? { - let rawValue: String? = nilOrValue(list[0]) - let cornerPoints: [CornerPoint?]? = nilOrValue(list[1]) - var format: BarcodeFormat? = nil - let formatEnumVal: Int? = nilOrValue(list[2]) - if let formatRawValue = formatEnumVal { - format = BarcodeFormat(rawValue: formatRawValue)! - } - let textValue: String? = nilOrValue(list[3]) + + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> DetectedBarcode? { + let rawValue: String? = nilOrValue(pigeonVar_list[0]) + let cornerPoints: [CornerPoint?]? = nilOrValue(pigeonVar_list[1]) + let format: BarcodeFormat? = nilOrValue(pigeonVar_list[2]) + let textValue: String? = nilOrValue(pigeonVar_list[3]) return DetectedBarcode( rawValue: rawValue, @@ -115,7 +149,7 @@ struct DetectedBarcode { return [ rawValue, cornerPoints, - format?.rawValue, + format, textValue, ] } @@ -126,9 +160,11 @@ struct CornerPoint { var x: Double var y: Double - static func fromList(_ list: [Any?]) -> CornerPoint? { - let x = list[0] as! Double - let y = list[1] as! Double + + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> CornerPoint? { + let x = pigeonVar_list[0] as! Double + let y = pigeonVar_list[1] as! Double return CornerPoint( x: x, @@ -143,21 +179,49 @@ struct CornerPoint { } } -private class BarcodeKitHostApiCodecReader: FlutterStandardReader { +private class PigeonPigeonCodecReader: FlutterStandardReader { override func readValue(ofType type: UInt8) -> Any? { switch type { - case 128: - return CameraOpenResponse.fromList(self.readValue() as! [Any?]) - default: - return super.readValue(ofType: type) + case 129: + let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?) + if let enumResultAsInt = enumResultAsInt { + return BarcodeFormat(rawValue: enumResultAsInt) + } + return nil + case 130: + let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?) + if let enumResultAsInt = enumResultAsInt { + return CameraLensDirection(rawValue: enumResultAsInt) + } + return nil + case 131: + return CameraOpenResponse.fromList(self.readValue() as! [Any?]) + case 132: + return DetectedBarcode.fromList(self.readValue() as! [Any?]) + case 133: + return CornerPoint.fromList(self.readValue() as! [Any?]) + default: + return super.readValue(ofType: type) } } } -private class BarcodeKitHostApiCodecWriter: FlutterStandardWriter { +private class PigeonPigeonCodecWriter: FlutterStandardWriter { override func writeValue(_ value: Any) { - if let value = value as? CameraOpenResponse { - super.writeByte(128) + if let value = value as? BarcodeFormat { + super.writeByte(129) + super.writeValue(value.rawValue) + } else if let value = value as? CameraLensDirection { + super.writeByte(130) + super.writeValue(value.rawValue) + } else if let value = value as? CameraOpenResponse { + super.writeByte(131) + super.writeValue(value.toList()) + } else if let value = value as? DetectedBarcode { + super.writeByte(132) + super.writeValue(value.toList()) + } else if let value = value as? CornerPoint { + super.writeByte(133) super.writeValue(value.toList()) } else { super.writeValue(value) @@ -165,20 +229,21 @@ private class BarcodeKitHostApiCodecWriter: FlutterStandardWriter { } } -private class BarcodeKitHostApiCodecReaderWriter: FlutterStandardReaderWriter { +private class PigeonPigeonCodecReaderWriter: FlutterStandardReaderWriter { override func reader(with data: Data) -> FlutterStandardReader { - return BarcodeKitHostApiCodecReader(data: data) + return PigeonPigeonCodecReader(data: data) } override func writer(with data: NSMutableData) -> FlutterStandardWriter { - return BarcodeKitHostApiCodecWriter(data: data) + return PigeonPigeonCodecWriter(data: data) } } -class BarcodeKitHostApiCodec: FlutterStandardMessageCodec { - static let shared = BarcodeKitHostApiCodec(readerWriter: BarcodeKitHostApiCodecReaderWriter()) +class PigeonPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable { + static let shared = PigeonPigeonCodec(readerWriter: PigeonPigeonCodecReaderWriter()) } + /// Generated protocol from Pigeon that represents a handler of messages from Flutter. protocol BarcodeKitHostApi { func openCamera(direction: CameraLensDirection, formats: [Int64], completion: @escaping (Result) -> Void) @@ -191,29 +256,29 @@ protocol BarcodeKitHostApi { /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. class BarcodeKitHostApiSetup { - /// The codec used by BarcodeKitHostApi. - static var codec: FlutterStandardMessageCodec { BarcodeKitHostApiCodec.shared } + static var codec: FlutterStandardMessageCodec { PigeonPigeonCodec.shared } /// Sets up an instance of `BarcodeKitHostApi` to handle messages through the `binaryMessenger`. - static func setUp(binaryMessenger: FlutterBinaryMessenger, api: BarcodeKitHostApi?) { - let openCameraChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.barcode_kit.BarcodeKitHostApi.openCamera", binaryMessenger: binaryMessenger, codec: codec) + static func setUp(binaryMessenger: FlutterBinaryMessenger, api: BarcodeKitHostApi?, messageChannelSuffix: String = "") { + let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" + let openCameraChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitHostApi.openCamera\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { openCameraChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let directionArg = CameraLensDirection(rawValue: args[0] as! Int)! + let directionArg = args[0] as! CameraLensDirection let formatsArg = args[1] as! [Int64] api.openCamera(direction: directionArg, formats: formatsArg) { result in switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) } } } } else { openCameraChannel.setMessageHandler(nil) } - let setOCREnabledChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.barcode_kit.BarcodeKitHostApi.setOCREnabled", binaryMessenger: binaryMessenger, codec: codec) + let setOCREnabledChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitHostApi.setOCREnabled\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { setOCREnabledChannel.setMessageHandler { message, reply in let args = message as! [Any?] @@ -228,7 +293,7 @@ class BarcodeKitHostApiSetup { } else { setOCREnabledChannel.setMessageHandler(nil) } - let closeCameraChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.barcode_kit.BarcodeKitHostApi.closeCamera", binaryMessenger: binaryMessenger, codec: codec) + let closeCameraChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitHostApi.closeCamera\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { closeCameraChannel.setMessageHandler { _, reply in do { @@ -241,7 +306,7 @@ class BarcodeKitHostApiSetup { } else { closeCameraChannel.setMessageHandler(nil) } - let pauseCameraChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.barcode_kit.BarcodeKitHostApi.pauseCamera", binaryMessenger: binaryMessenger, codec: codec) + let pauseCameraChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitHostApi.pauseCamera\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { pauseCameraChannel.setMessageHandler { _, reply in do { @@ -254,7 +319,7 @@ class BarcodeKitHostApiSetup { } else { pauseCameraChannel.setMessageHandler(nil) } - let resumeCameraChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.barcode_kit.BarcodeKitHostApi.resumeCamera", binaryMessenger: binaryMessenger, codec: codec) + let resumeCameraChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitHostApi.resumeCamera\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { resumeCameraChannel.setMessageHandler { _, reply in do { @@ -267,7 +332,7 @@ class BarcodeKitHostApiSetup { } else { resumeCameraChannel.setMessageHandler(nil) } - let setTorchChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.barcode_kit.BarcodeKitHostApi.setTorch", binaryMessenger: binaryMessenger, codec: codec) + let setTorchChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitHostApi.setTorch\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { setTorchChannel.setMessageHandler { message, reply in let args = message as! [Any?] @@ -284,75 +349,80 @@ class BarcodeKitHostApiSetup { } } } -private class BarcodeKitFlutterApiCodecReader: FlutterStandardReader { - override func readValue(ofType type: UInt8) -> Any? { - switch type { - case 128: - return CornerPoint.fromList(self.readValue() as! [Any?]) - case 129: - return DetectedBarcode.fromList(self.readValue() as! [Any?]) - default: - return super.readValue(ofType: type) - } - } -} - -private class BarcodeKitFlutterApiCodecWriter: FlutterStandardWriter { - override func writeValue(_ value: Any) { - if let value = value as? CornerPoint { - super.writeByte(128) - super.writeValue(value.toList()) - } else if let value = value as? DetectedBarcode { - super.writeByte(129) - super.writeValue(value.toList()) - } else { - super.writeValue(value) - } - } -} - -private class BarcodeKitFlutterApiCodecReaderWriter: FlutterStandardReaderWriter { - override func reader(with data: Data) -> FlutterStandardReader { - return BarcodeKitFlutterApiCodecReader(data: data) - } - - override func writer(with data: NSMutableData) -> FlutterStandardWriter { - return BarcodeKitFlutterApiCodecWriter(data: data) - } -} - -class BarcodeKitFlutterApiCodec: FlutterStandardMessageCodec { - static let shared = BarcodeKitFlutterApiCodec(readerWriter: BarcodeKitFlutterApiCodecReaderWriter()) +/// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift. +protocol BarcodeKitFlutterApiProtocol { + /// Caleld from the host when a barcode is detected. + func onBarcodeScanned(barcode barcodeArg: DetectedBarcode, completion: @escaping (Result) -> Void) + /// Called from the host when text is detected. + func onTextDetected(text textArg: String, completion: @escaping (Result) -> Void) + /// Called from the host when the torch state changes. + func onTorchStateChanged(enabled enabledArg: Bool, completion: @escaping (Result) -> Void) } - -/// Generated class from Pigeon that represents Flutter messages that can be called from Swift. -class BarcodeKitFlutterApi { +class BarcodeKitFlutterApi: BarcodeKitFlutterApiProtocol { private let binaryMessenger: FlutterBinaryMessenger - init(binaryMessenger: FlutterBinaryMessenger){ + private let messageChannelSuffix: String + init(binaryMessenger: FlutterBinaryMessenger, messageChannelSuffix: String = "") { self.binaryMessenger = binaryMessenger + self.messageChannelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" } - var codec: FlutterStandardMessageCodec { - return BarcodeKitFlutterApiCodec.shared + var codec: PigeonPigeonCodec { + return PigeonPigeonCodec.shared } /// Caleld from the host when a barcode is detected. - func onBarcodeScanned(barcode barcodeArg: DetectedBarcode, completion: @escaping () -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.barcode_kit.BarcodeKitFlutterApi.onBarcodeScanned", binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([barcodeArg] as [Any?]) { _ in - completion() + func onBarcodeScanned(barcode barcodeArg: DetectedBarcode, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitFlutterApi.onBarcodeScanned\(messageChannelSuffix)" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([barcodeArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } } } /// Called from the host when text is detected. - func onTextDetected(text textArg: String, completion: @escaping () -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.barcode_kit.BarcodeKitFlutterApi.onTextDetected", binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([textArg] as [Any?]) { _ in - completion() + func onTextDetected(text textArg: String, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitFlutterApi.onTextDetected\(messageChannelSuffix)" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([textArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } } } /// Called from the host when the torch state changes. - func onTorchStateChanged(enabled enabledArg: Bool, completion: @escaping () -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.barcode_kit.BarcodeKitFlutterApi.onTorchStateChanged", binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([enabledArg] as [Any?]) { _ in - completion() + func onTorchStateChanged(enabled enabledArg: Bool, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitFlutterApi.onTorchStateChanged\(messageChannelSuffix)" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([enabledArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } } } } diff --git a/ios/Classes/SwiftBarcodeKitPlugin.swift b/ios/Classes/SwiftBarcodeKitPlugin.swift index d6718c0..150a244 100644 --- a/ios/Classes/SwiftBarcodeKitPlugin.swift +++ b/ios/Classes/SwiftBarcodeKitPlugin.swift @@ -206,7 +206,7 @@ public class SwiftBarcodeKitPlugin: NSObject, FlutterPlugin , BarcodeKitHostApi, DispatchQueue.main.async { - self.flutterApi.onTextDetected(text: topCandidate.string,completion: { + self.flutterApi.onTextDetected(text: topCandidate.string,completion: {_ in }) } @@ -269,7 +269,7 @@ public class SwiftBarcodeKitPlugin: NSObject, FlutterPlugin , BarcodeKitHostApi, })?.key, textValue: barcodeMetadataObject.stringValue ) - flutterApi.onBarcodeScanned(barcode: barcode,completion: { + flutterApi.onBarcodeScanned(barcode: barcode,completion: {_ in }) } @@ -294,7 +294,7 @@ public class SwiftBarcodeKitPlugin: NSObject, FlutterPlugin , BarcodeKitHostApi, case "torchMode": // off = 0; on = 1; auto = 2; let state = change?[.newKey] as? Int - flutterApi.onTorchStateChanged(enabled: state == 1, completion: { + flutterApi.onTorchStateChanged(enabled: state == 1, completion: {_ in }) diff --git a/ios/barcode_kit.podspec b/ios/mtrust_barcode_kit.podspec similarity index 57% rename from ios/barcode_kit.podspec rename to ios/mtrust_barcode_kit.podspec index 15d3b2e..2764616 100644 --- a/ios/barcode_kit.podspec +++ b/ios/mtrust_barcode_kit.podspec @@ -3,15 +3,18 @@ # Run `pod lib lint barcode_kit.podspec` to validate before publishing. # Pod::Spec.new do |s| - s.name = 'barcode_kit' + s.name = 'mtrust_barcode_kit' s.version = '0.0.1' - s.summary = 'A new Flutter plugin project.' + s.summary = 'Read barcodes using the camera' s.description = <<-DESC -A new Flutter plugin project. + Barcode-Kit is a flutter package that allows you to read barcodes + using the camera. It uses native textures to display the camera feed and the + barcode overlay. It is built on top of the Google ML Kit and iOS Vision for + barcode scanning. DESC - s.homepage = 'http://example.com' + s.homepage = 'https://github.com/emdgroup/mtrust-barcode-kit' s.license = { :file => '../LICENSE' } - s.author = { 'Your Company' => 'email@example.com' } + s.author = { 'EMD Group' => 'info@emdgroup.com' } s.source = { :path => '.' } s.source_files = 'Classes/**/*' s.dependency 'Flutter' diff --git a/lib/src/barcode_kit.dart b/lib/src/barcode_kit.dart index fc86f0a..15e48c3 100644 --- a/lib/src/barcode_kit.dart +++ b/lib/src/barcode_kit.dart @@ -15,7 +15,7 @@ typedef OnTextDetectedCallback = void Function(String text); class BarcodeKit extends BarcodeKitFlutterApi { /// Create a new instance of the plugin. BarcodeKit() { - BarcodeKitFlutterApi.setup(this); + BarcodeKitFlutterApi.setUp(this); } final BarcodeKitHostApi _host = BarcodeKitHostApi(); diff --git a/lib/src/barcode_kit_view.dart b/lib/src/barcode_kit_view.dart index 07c57b7..c04bd1b 100644 --- a/lib/src/barcode_kit_view.dart +++ b/lib/src/barcode_kit_view.dart @@ -357,7 +357,9 @@ class _BarcodeKitViewState extends State void dispose() { _barcodeKitPlugin ..closeCamera() + ..onTextDetectedCallback = null ..onBarcodeScannedCallback = null; + _animationController.dispose(); super.dispose(); } @@ -385,7 +387,7 @@ class _BarcodeKitViewState extends State ).value; return ColorFiltered( colorFilter: ColorFilter.mode( - widget.backdropColor.withOpacity(value * 0.2), + widget.backdropColor.withAlpha((value * 55).toInt()), BlendMode.srcATop, ), child: ImageFiltered( diff --git a/lib/src/perspective.dart b/lib/src/perspective.dart index 1734a78..8b674fe 100644 --- a/lib/src/perspective.dart +++ b/lib/src/perspective.dart @@ -137,6 +137,7 @@ class PerspectiveTransform extends Equatable { List get props => [_matrix]; } +// ignore: must_be_immutable class _PerspectiveMatrix extends ListBase with EquatableMixin { _PerspectiveMatrix(List> matrix) : _values = matrix.reduce((value, element) => [...value, ...element]); diff --git a/lib/src/pigeon.dart b/lib/src/pigeon.dart index ee87657..d9bae8f 100644 --- a/lib/src/pigeon.dart +++ b/lib/src/pigeon.dart @@ -1,6 +1,6 @@ -// Autogenerated from Pigeon (v10.1.6), do not edit directly. +// Autogenerated from Pigeon (v24.1.0), do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -8,6 +8,23 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + +List wrapResponse({Object? result, PlatformException? error, bool empty = false}) { + if (empty) { + return []; + } + if (error == null) { + return [result]; + } + return [error.code, error.message, error.details]; +} + enum BarcodeFormat { aztec, codabar, @@ -87,7 +104,7 @@ class DetectedBarcode { return [ rawValue, cornerPoints, - format?.index, + format, textValue, ]; } @@ -97,8 +114,7 @@ class DetectedBarcode { return DetectedBarcode( rawValue: result[0] as String?, cornerPoints: (result[1] as List?)?.cast(), - format: - result[2] != null ? BarcodeFormat.values[result[2]! as int] : null, + format: result[2] as BarcodeFormat?, textValue: result[3] as String?, ); } @@ -130,12 +146,28 @@ class CornerPoint { } } -class _BarcodeKitHostApiCodec extends StandardMessageCodec { - const _BarcodeKitHostApiCodec(); + +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is CameraOpenResponse) { - buffer.putUint8(128); + if (value is int) { + buffer.putUint8(4); + buffer.putInt64(value); + } else if (value is BarcodeFormat) { + buffer.putUint8(129); + writeValue(buffer, value.index); + } else if (value is CameraLensDirection) { + buffer.putUint8(130); + writeValue(buffer, value.index); + } else if (value is CameraOpenResponse) { + buffer.putUint8(131); + writeValue(buffer, value.encode()); + } else if (value is DetectedBarcode) { + buffer.putUint8(132); + writeValue(buffer, value.encode()); + } else if (value is CornerPoint) { + buffer.putUint8(133); writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); @@ -145,8 +177,18 @@ class _BarcodeKitHostApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 129: + final int? value = readValue(buffer) as int?; + return value == null ? null : BarcodeFormat.values[value]; + case 130: + final int? value = readValue(buffer) as int?; + return value == null ? null : CameraLensDirection.values[value]; + case 131: return CameraOpenResponse.decode(readValue(buffer)!); + case 132: + return DetectedBarcode.decode(readValue(buffer)!); + case 133: + return CornerPoint.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); } @@ -157,56 +199,58 @@ class BarcodeKitHostApi { /// Constructor for [BarcodeKitHostApi]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - BarcodeKitHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - - static const MessageCodec codec = _BarcodeKitHostApiCodec(); - - Future openCamera( - CameraLensDirection arg_direction, List arg_formats) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.barcode_kit.BarcodeKitHostApi.openCamera', codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_direction.index, arg_formats]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + BarcodeKitHostApi({BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) + : pigeonVar_binaryMessenger = binaryMessenger, + pigeonVar_messageChannelSuffix = messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + final BinaryMessenger? pigeonVar_binaryMessenger; + + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); + + final String pigeonVar_messageChannelSuffix; + + Future openCamera(CameraLensDirection direction, List formats) async { + final String pigeonVar_channelName = 'dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitHostApi.openCamera$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([direction, formats]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); - } else if (replyList[0] == null) { + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as CameraOpenResponse?)!; + return (pigeonVar_replyList[0] as CameraOpenResponse?)!; } } - Future setOCREnabled(bool arg_enabled) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.barcode_kit.BarcodeKitHostApi.setOCREnabled', codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_enabled]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + Future setOCREnabled(bool enabled) async { + final String pigeonVar_channelName = 'dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitHostApi.setOCREnabled$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([enabled]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; @@ -214,20 +258,21 @@ class BarcodeKitHostApi { } Future closeCamera() async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.barcode_kit.BarcodeKitHostApi.closeCamera', codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + final String pigeonVar_channelName = 'dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitHostApi.closeCamera$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send(null) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; @@ -235,20 +280,21 @@ class BarcodeKitHostApi { } Future pauseCamera() async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.barcode_kit.BarcodeKitHostApi.pauseCamera', codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + final String pigeonVar_channelName = 'dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitHostApi.pauseCamera$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send(null) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; @@ -256,42 +302,43 @@ class BarcodeKitHostApi { } Future resumeCamera() async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.barcode_kit.BarcodeKitHostApi.resumeCamera', codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + final String pigeonVar_channelName = 'dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitHostApi.resumeCamera$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send(null) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future setTorch(bool arg_enabled) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.barcode_kit.BarcodeKitHostApi.setTorch', codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_enabled]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + Future setTorch(bool enabled) async { + final String pigeonVar_channelName = 'dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitHostApi.setTorch$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([enabled]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; @@ -299,38 +346,10 @@ class BarcodeKitHostApi { } } -class _BarcodeKitFlutterApiCodec extends StandardMessageCodec { - const _BarcodeKitFlutterApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is CornerPoint) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is DetectedBarcode) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return CornerPoint.decode(readValue(buffer)!); - case 129: - return DetectedBarcode.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - abstract class BarcodeKitFlutterApi { - static const MessageCodec codec = _BarcodeKitFlutterApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); - /// Called from the host when a barcode is detected. + /// Caleld from the host when a barcode is detected. void onBarcodeScanned(DetectedBarcode barcode); /// Called from the host when text is detected. @@ -339,65 +358,80 @@ abstract class BarcodeKitFlutterApi { /// Called from the host when the torch state changes. void onTorchStateChanged(bool enabled); - static void setup(BarcodeKitFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setUp(BarcodeKitFlutterApi? api, {BinaryMessenger? binaryMessenger, String messageChannelSuffix = '',}) { + messageChannelSuffix = messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.barcode_kit.BarcodeKitFlutterApi.onBarcodeScanned', - codec, + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( + 'dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitFlutterApi.onBarcodeScanned$messageChannelSuffix', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + pigeonVar_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.barcode_kit.BarcodeKitFlutterApi.onBarcodeScanned was null.'); + 'Argument for dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitFlutterApi.onBarcodeScanned was null.'); final List args = (message as List?)!; final DetectedBarcode? arg_barcode = (args[0] as DetectedBarcode?); assert(arg_barcode != null, - 'Argument for dev.flutter.pigeon.barcode_kit.BarcodeKitFlutterApi.onBarcodeScanned was null, expected non-null DetectedBarcode.'); - api.onBarcodeScanned(arg_barcode!); - return; + 'Argument for dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitFlutterApi.onBarcodeScanned was null, expected non-null DetectedBarcode.'); + try { + api.onBarcodeScanned(arg_barcode!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse(error: PlatformException(code: 'error', message: e.toString())); + } }); } } { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.barcode_kit.BarcodeKitFlutterApi.onTextDetected', - codec, + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( + 'dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitFlutterApi.onTextDetected$messageChannelSuffix', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + pigeonVar_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.barcode_kit.BarcodeKitFlutterApi.onTextDetected was null.'); + 'Argument for dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitFlutterApi.onTextDetected was null.'); final List args = (message as List?)!; final String? arg_text = (args[0] as String?); assert(arg_text != null, - 'Argument for dev.flutter.pigeon.barcode_kit.BarcodeKitFlutterApi.onTextDetected was null, expected non-null String.'); - api.onTextDetected(arg_text!); - return; + 'Argument for dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitFlutterApi.onTextDetected was null, expected non-null String.'); + try { + api.onTextDetected(arg_text!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse(error: PlatformException(code: 'error', message: e.toString())); + } }); } } { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.barcode_kit.BarcodeKitFlutterApi.onTorchStateChanged', - codec, + final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( + 'dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitFlutterApi.onTorchStateChanged$messageChannelSuffix', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + pigeonVar_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.barcode_kit.BarcodeKitFlutterApi.onTorchStateChanged was null.'); + 'Argument for dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitFlutterApi.onTorchStateChanged was null.'); final List args = (message as List?)!; final bool? arg_enabled = (args[0] as bool?); assert(arg_enabled != null, - 'Argument for dev.flutter.pigeon.barcode_kit.BarcodeKitFlutterApi.onTorchStateChanged was null, expected non-null bool.'); - api.onTorchStateChanged(arg_enabled!); - return; + 'Argument for dev.flutter.pigeon.mtrust_barcode_kit.BarcodeKitFlutterApi.onTorchStateChanged was null, expected non-null bool.'); + try { + api.onTorchStateChanged(arg_enabled!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse(error: PlatformException(code: 'error', message: e.toString())); + } }); } } diff --git a/pubspec.yaml b/pubspec.yaml index bf2e220..11d4543 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,16 +16,16 @@ dependencies: permission_handler: ^11.3.1 plugin_platform_interface: ^2.1.8 dev_dependencies: - flutter_lints: ^2.0.0 + flutter_lints: ^5.0.0 flutter_test: sdk: flutter - pigeon: ^10.1.0 - very_good_analysis: ^5.0.0+1 + pigeon: ^24.1.0 + very_good_analysis: ^7.0.0 flutter: plugin: platforms: android: - package: com.emddigital.barcode_kit + package: com.emddigital.mtrust_barcode_kit pluginClass: BarcodeKitPlugin ios: pluginClass: BarcodeKitPlugin