QRKit is a Kotlin Multiplatform library for Qr-Scan in your Android, iOS And Desktop App.
![QRKit_Compose Multiplatfrom_banner](https://private-user-images.githubusercontent.com/143475887/346463818-6510ae51-6d79-4259-9654-61fb9d9e6cdb.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIzOTA3MTAsIm5iZiI6MTcyMjM5MDQxMCwicGF0aCI6Ii8xNDM0NzU4ODcvMzQ2NDYzODE4LTY1MTBhZTUxLTZkNzktNDI1OS05NjU0LTYxZmI5ZDllNmNkYi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzMxJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDczMVQwMTQ2NTBaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT00M2FhY2JjNzQ1MGY5NDQ5NzczMWZmOGE4Y2IzZDQ3MzhkNzliYTE1OGFjNjk3OTNiZTFjMGZjZjhjOTlmOTk3JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.EArjudTGnPFCWEJ_LlVuLE9kRgvHwRjGYxoFWcfpaO4)
Add the dependency to your build.gradle.kts
file:
commonMain.dependencies {
implementation("network.chaintech:qr-kit:1.0.8")
}
QrDemo.mp4
MicrosoftTeams-video.mp4
QRKit_Compose.Multiplatfrom_desktop.mov
- Android : Include this at root level in your AndroidManifest.xml:
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.FLASHLIGHT"/>
- iOS : Add below key to the Info.plist in your xcode project:
<key>NSCameraUsageDescription</key><string>$(PRODUCT_NAME) camera description.</string>
<key>NSPhotoLibraryUsageDescription</key><string>$(PRODUCT_NAME)photos description.</string>
QrScanner(
modifier: Modifier,
flashlightOn: Boolean,
openImagePicker: Boolean,
onCompletion: (String) -> Unit,
imagePickerHandler: (Boolean) -> Unit,
onFailure: (String) -> Unit
)
modifier
: Modifier for modifying the layout of the QR scanner.flashlightOn
: Boolean indicating whether the flashlight is turned on.openImagePicker
: Boolean indicating whether to launch the picker for selecting images.imagePickerHandler
: Callback invoked to indicate the status of the gallery, whether it's open or closed.onFailure
: Callback invoked when there's a failure during QR code scanning.
QRCodeImage(
url: String,
contentDescription: String?,
modifier: Modifier = Modifier,
alignment: Alignment = Alignment.Center,
contentScale: ContentScale = ContentScale.Fit,
alpha: Float = DefaultAlpha,
colorFilter: ColorFilter? = null,
filterQuality: FilterQuality = DrawScope.DefaultFilterQuality,
onSuccess: (ImageBitmap) -> Unit = { qrImage -> },
onFailure: (String) -> Unit = { message -> }
)
- And also use below function to generate qrcode
fun generateQrCode(
url: String,
onSuccess: (String, ImageBitmap) -> Unit,
onFailure: (String) -> Unit
) {
try {
val imageBitmap = generateCode(url)
onSuccess(url, imageBitmap)
} catch (e: Exception) {
onFailure("${e.message}")
}
}
url
: The URL of the QR code image to be displayed.contentDescription
: A textual description of the image content for accessibility purposes. It's optional.modifier
: Modifier for modifying the layout of the QR code image.alignment
: Alignment of the QR code image within its layout bounds. Default is Alignment.Center.contentScale
: The scale strategy for fitting the QR code image content within its layout bounds. Default is ContentScale.Fit.alpha
: The opacity of the QR code image, ranging from 0.0 (fully transparent) to 1.0 (fully opaque). Default is DefaultAlpha.colorFilter
: A color filter to apply to the QR code image. Default is null.filterQuality
: The quality of the filtering applied to the QR code image. Default is DrawScope.DefaultFilterQuality.onSuccess
: Callback invoked when the QR code image is successfully loaded and decoded, passing the decoded ImageBitmap as a parameter.onFailure
: Callback invoked when there's a failure during loading or decoding the QR code image, passing an error message as a parameter.
- Compose Multiplatform
- CameraX Jetpack library
- ML Kit
For Image Picker we had used this CMP Pick n Crop Library
- for more follow this class -> App.kt
- Want to understand in more detail? Checkout this Medium Article
- Connect with us on LinkedIn