@@ -8,6 +8,7 @@ import android.net.Uri
88import android.os.Handler
99import android.os.Looper
1010import android.util.Size
11+ import androidx.annotation.OptIn
1112import androidx.camera.core.CameraSelector
1213import androidx.camera.core.ExperimentalGetImage
1314import androidx.camera.core.ExperimentalLensFacing
@@ -25,6 +26,7 @@ import io.flutter.view.TextureRegistry
2526import java.io.File
2627import com.google.mlkit.vision.barcode.ZoomSuggestionOptions
2728
29+ @OptIn(ExperimentalGetImage ::class )
2830class MobileScannerHandler (
2931 private val activity : Activity ,
3032 private val barcodeHandler : BarcodeHandler ,
@@ -175,7 +177,7 @@ class MobileScannerHandler(
175177 val invertImage: Boolean = call.argument<Boolean >(" invertImage" ) ? : false
176178 val initialZoom: Double? = call.argument<Double ?>(" initialZoom" )
177179
178- val barcodeScannerOptions: BarcodeScannerOptions ? = buildBarcodeScannerOptions(formats, autoZoom)
180+ val barcodeScannerOptions: BarcodeScannerOptions = buildBarcodeScannerOptions(formats, autoZoom)
179181
180182 val position =
181183 if (facing == 0 ) CameraSelector .DEFAULT_FRONT_CAMERA else CameraSelector .DEFAULT_BACK_CAMERA
@@ -267,7 +269,7 @@ class MobileScannerHandler(
267269 try {
268270 mobileScanner!! .stop(force)
269271 result.success(null )
270- } catch (e : AlreadyStopped ) {
272+ } catch (_ : AlreadyStopped ) {
271273 result.success(null )
272274 }
273275 }
@@ -294,10 +296,10 @@ class MobileScannerHandler(
294296 try {
295297 mobileScanner!! .setScale(call.arguments as Double )
296298 result.success(null )
297- } catch (e : ZoomWhenStopped ) {
299+ } catch (_ : ZoomWhenStopped ) {
298300 result.error(
299301 MobileScannerErrorCodes .SET_SCALE_WHEN_STOPPED_ERROR , MobileScannerErrorCodes .SET_SCALE_WHEN_STOPPED_ERROR_MESSAGE , null )
300- } catch (e : ZoomNotInRange ) {
302+ } catch (_ : ZoomNotInRange ) {
301303 result.error(
302304 MobileScannerErrorCodes .GENERIC_ERROR , MobileScannerErrorCodes .INVALID_ZOOM_SCALE_ERROR_MESSAGE , null )
303305 }
@@ -307,15 +309,15 @@ class MobileScannerHandler(
307309 try {
308310 mobileScanner!! .setZoomRatio(scale.toDouble())
309311 return true
310- } catch (e : ZoomWhenStopped ) { }
312+ } catch (_ : ZoomWhenStopped ) { }
311313 return false
312314 }
313315
314316 private fun resetScale (result : MethodChannel .Result ) {
315317 try {
316318 mobileScanner!! .resetScale()
317319 result.success(null )
318- } catch (e : ZoomWhenStopped ) {
320+ } catch (_ : ZoomWhenStopped ) {
319321 result.error(
320322 MobileScannerErrorCodes .SET_SCALE_WHEN_STOPPED_ERROR , MobileScannerErrorCodes .SET_SCALE_WHEN_STOPPED_ERROR_MESSAGE , null )
321323 }
@@ -327,8 +329,8 @@ class MobileScannerHandler(
327329 result.success(null )
328330 }
329331
330- private fun buildBarcodeScannerOptions (formats : List <Int >? , autoZoom : Boolean ): BarcodeScannerOptions ? {
331- val builder : BarcodeScannerOptions .Builder ?
332+ private fun buildBarcodeScannerOptions (formats : List <Int >? , autoZoom : Boolean ): BarcodeScannerOptions {
333+ val builder : BarcodeScannerOptions .Builder
332334 if (formats == null ) {
333335 builder = BarcodeScannerOptions .Builder ()
334336 } else {
@@ -338,10 +340,10 @@ class MobileScannerHandler(
338340 formatsList.add(BarcodeFormats .fromRawValue(formatValue).intValue)
339341 }
340342
341- if (formatsList.size == 1 ) {
342- builder = BarcodeScannerOptions .Builder ().setBarcodeFormats(formatsList.first())
343+ builder = if (formatsList.size == 1 ) {
344+ BarcodeScannerOptions .Builder ().setBarcodeFormats(formatsList.first())
343345 } else {
344- builder = BarcodeScannerOptions .Builder ().setBarcodeFormats(
346+ BarcodeScannerOptions .Builder ().setBarcodeFormats(
345347 formatsList.first(),
346348 * formatsList.subList(1 , formatsList.size).toIntArray()
347349 )
@@ -394,7 +396,7 @@ class MobileScannerHandler(
394396 try {
395397 mobileScanner?.setFocus(dx, dy)
396398 result.success(null )
397- } catch (e : ZoomWhenStopped ) {
399+ } catch (_ : ZoomWhenStopped ) {
398400 result.error(
399401 MobileScannerErrorCodes .GENERIC_ERROR ,
400402 " Cannot set focus when camera is stopped." ,
0 commit comments