RafaelBarbosatec / qr_code_dart_scan

A QR code scanner that works on both iOS and Android using dart decoder.
MIT License
19 stars 19 forks source link

Camera lens direction detection on web version #15

Closed thierrylee closed 8 months ago

thierrylee commented 8 months ago

Hello,

I had an issue with the TypeCamera that occurred on the web version: even though I specified to use the back camera, the front one was used. I believe this is due to this part of the code:

lib/src/qr_code_dart_scan_view.dart From line 100

void _initController() async {
    final cameras = await availableCameras();
    var camera = cameras.first;
    if (widget.typeCamera == TypeCamera.front && cameras.length > 1) {
      camera = cameras[1];
    }

I think you should check the camera.lensDirection to better detect the correct camera to use, with this code:

void _initController() async {
    final CameraLensDirection lensDirection;
    switch (widget.typeCamera) {
      case TypeCamera.back:
        lensDirection = CameraLensDirection.back;
        break;
      case TypeCamera.front:
        lensDirection = CameraLensDirection.front;
        break;
    }

    final cameras = await availableCameras();
    final camera = cameras.firstWhere((camera) => camera.lensDirection == lensDirection, orElse: () => cameras.first);

I tried to open a pull request but couldn't (can't push a new branch), thus making this issue. Best regards,

PS: I did not have the time to try this fix yet, I'll keep you updated

thierrylee commented 8 months ago

Hi again, I just tried and it does fix the issue !

Although not ideal, I will be using a forked version until next update!

RafaelBarbosatec commented 8 months ago

Hi @thierrylee ! Thanks for report it. It's strange, do you can't open a pull request? Ok, I'll fix it. Thanks!

RafaelBarbosatec commented 8 months ago

Fixed in 0.7.6

thierrylee commented 8 months ago

Thanks !