juliansteenbakker / mobile_scanner

A universal scanner for Flutter based on MLKit. Uses CameraX on Android and AVFoundation on iOS.
BSD 3-Clause "New" or "Revised" License
904 stars 520 forks source link

Official document error #1240

Open jsleemaster opened 2 weeks ago

jsleemaster commented 2 weeks ago

Error

The getter 'hasCameraPermission' isn't defined for the type 'MobileScannerState'. Try importing the library that defines 'hasCameraPermission', correcting the name to the name of an existing getter, or defining a getter or field named 'hasCameraPermission'.

There is an error with the hasCameraPermission option in the idChangeAppLifeState method part in the official document. Which part should it be replaced with? Can you correct it?

Currently, I am checking with isInitialized option.

navaronbracke commented 2 weeks ago

This getter is defined here: https://github.com/juliansteenbakker/mobile_scanner/blob/master/lib/src/objects/mobile_scanner_state.dart#L66

What version of mobile_scanner are you using? The getter was introduced in version 6.0.0, as stated in the changelog.

https://github.com/juliansteenbakker/mobile_scanner/blob/master/CHANGELOG.md#600

If you do not want to upgrade to that version, you can just do the check yourself, too.

For that, you'll need to check both isInitialized and error?.errorCode != MobileScannerErrorCode.permissionDenied

hailuongsl97 commented 1 week ago

Screenshot 2024-11-21 at 09 38 22 Hello @navaronbracke I same issue! I has check code, default isInitialized is false => hasCameraPermission is false and isInitialized set is true when call start() please fix this issue

navaronbracke commented 1 week ago

@hailuongsl97 What version of mobile_scanner are you using? The getter hasCameraPermission is introduced in version 6.0.0, with a workaround for version 5.0.0, as stated above.

hailuongsl97 commented 1 week ago

@hailuongsl97 What version of mobile_scanner are you using? The getter hasCameraPermission is introduced in version 6.0.0, with a workaround for version 5.0.0, as stated above.

I use mobile_scanner v 6.0.2

navaronbracke commented 1 week ago

@hailuongsl97 I do not understand what problem your are encountering? You can use hasCameraPermission in didChangeAppLifecycleState, to determine if the controller should be started when the application is resumed. See the example at https://github.com/juliansteenbakker/mobile_scanner/blob/master/example/lib/barcode_scanner_controller.dart#L62-L81

Or are you referring to a different issue?