Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1507: Mobile scanner does not recognize barcodes #1524

Merged
merged 3 commits into from
Jul 3, 2024

Conversation

f1sh1918
Copy link
Contributor

@f1sh1918 f1sh1918 commented Jul 1, 2024

Short description

Some android cameras don't recognize barcodes due to some upstream android camera issues.
This seem to be related to the defaultCamera resolution each device uses
juliansteenbakker/mobile_scanner#698
Its not that easy to detect which cameras may be issued to not apply this on all android devices.

Proposed changes

  • provide a fixed camera resolution for specific android models

Side effects

  • aspect ratio is not correct. so we can discuss if this is good enough, because it looks ugly
  • i played around with the values but didn't find a working solution with correct aspect ratio so far

Resolved issues

Related: #1507

Note

I'm not sure if we should set the cameraResolution to all android devices because it looks ugly. But its also difficult to maintain particular models, so let me know what you think. We could keep the issue open if new devices will be reported.

Testing (dev only)

This bugfix is only testable with the particular device, but you can just check if the controller applies, if you add your model to devicesWithoutQRCodeDetection list and check if the resolution of the camera changes

@f1sh1918 f1sh1918 marked this pull request as draft July 1, 2024 18:08
@f1sh1918 f1sh1918 marked this pull request as ready for review July 1, 2024 18:26
@f1sh1918 f1sh1918 force-pushed the 1507-mobile-scanner-does-not-recognize-barcodes branch from d66b5c8 to 5bf5e8c Compare July 1, 2024 19:06
returnImage: false,
);
torchEnabled: false, detectionSpeed: DetectionSpeed.normal, formats: [BarcodeFormat.qrCode], returnImage: false);
final MobileScannerController _controllerCameraResolution = MobileScannerController(
Copy link
Contributor Author

@f1sh1918 f1sh1918 Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure how i can avoid defining different controllers twice since cameraResolution has no setter to change it
I hope i could extend it somehow just by cameraResolution

@f1sh1918 f1sh1918 force-pushed the 1507-mobile-scanner-does-not-recognize-barcodes branch 2 times, most recently from 2bbb2ef to f98cd05 Compare July 2, 2024 07:08
@f1sh1918 f1sh1918 force-pushed the 1507-mobile-scanner-does-not-recognize-barcodes branch from f98cd05 to 1641778 Compare July 2, 2024 07:10
Comment on lines 40 to +47
final MobileScannerController _controller = MobileScannerController(
torchEnabled: false,
detectionSpeed: DetectionSpeed.normal,
formats: [BarcodeFormat.qrCode],
returnImage: false,
);
torchEnabled: false, detectionSpeed: DetectionSpeed.normal, formats: [BarcodeFormat.qrCode], returnImage: false);
final MobileScannerController _controllerPredefinedCameraResolution = MobileScannerController(
torchEnabled: false,
detectionSpeed: DetectionSpeed.normal,
formats: [BarcodeFormat.qrCode],
returnImage: false,
cameraResolution: const Size(640, 480));
Copy link
Member

@michael-markl michael-markl Jul 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not entirely sure if it works, but you could make the _controller non-final and simply overwrite if/once we detect it is a problematic device (instead of setting the _hasCameraIssues flag).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does not work

Copy link
Member

@michael-markl michael-markl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good (enough) to me :D Let's see if this fixes it for the reports that we got.

If you have tested on a separate device and this should be mergable I think :D

@f1sh1918
Copy link
Contributor Author

f1sh1918 commented Jul 3, 2024

Looks good (enough) to me :D Let's see if this fixes it for the reports that we got.

If you have tested on a separate device and this should be mergable I think :D

Yes since i adjusted some minor things, i will test it today again with the real device

@f1sh1918
Copy link
Contributor Author

f1sh1918 commented Jul 3, 2024

@michael-markl i just tested it again and realized that this implementation needed a future builder to handle async functions in the initState
Not very nice to need so much additional code just for async functions in initState but i think its not avoidable.
Without the changed state will not be recognized from the widget
Some good infos initState and StateManagement in flutter
https://www.dhiwise.com/post/the-role-of-flutter-linitstate-in-state-management

@f1sh1918 f1sh1918 merged commit 2dedc36 into main Jul 3, 2024
1 check passed
@f1sh1918 f1sh1918 deleted the 1507-mobile-scanner-does-not-recognize-barcodes branch July 3, 2024 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants