-
-
Notifications
You must be signed in to change notification settings - Fork 287
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
feat: ML Kit scanner #893
feat: ML Kit scanner #893
Conversation
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the iOS native changes here are not tested
@@ -41,6 +41,8 @@ dependencies: | |||
path: ../smooth_ui_library | |||
url_launcher: ^6.0.17 | |||
visibility_detector: ^0.2.2 | |||
google_ml_barcode_scanner: ^0.0.2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYK
This is a standalone barcode scanner from the original google_ml_kit plugin.
Reason as to why I extracted the original plugin is because of unnecessary imports creates a huge file size of app during build.
final Size size = MediaQuery.of(context).size; | ||
// calculate scale depending on screen and camera ratios | ||
// this is actually size.aspectRatio / (1 / camera.aspectRatio) | ||
// because camera preview size is received as landscape | ||
// but we're calculating for portrait orientation | ||
double scale = size.aspectRatio * _controller!.value.aspectRatio; | ||
|
||
// to prevent scaling down, invert the value | ||
if (scale < 1) { | ||
scale = 1 / scale; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This calculation is from here:
https://stackoverflow.com/a/61487358/13313941
without that the camera looks really streched when moving around
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If so please put that in the code's comment, not here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough
if (!mounted) { | ||
return; | ||
} | ||
_controller?.setFocusMode(FocusMode.auto); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also set it to manual and allow for focusing on a certain focus offset as there is the option in the native android app, which is relevant for devices with poor autofocus
@teolemon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ScaffoldMessenger.of(context) | ||
.showSnackBar(const SnackBar(content: Text('Ok'))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea
final Size size = MediaQuery.of(context).size; | ||
// calculate scale depending on screen and camera ratios | ||
// this is actually size.aspectRatio / (1 / camera.aspectRatio) | ||
// because camera preview size is received as landscape | ||
// but we're calculating for portrait orientation | ||
double scale = size.aspectRatio * _controller!.value.aspectRatio; | ||
|
||
// to prevent scaling down, invert the value | ||
if (scale < 1) { | ||
scale = 1 / scale; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If so please put that in the code's comment, not here.
@monsieurtanuki just made ee0249b, this is most abstraction which makes sense, since the QRView from qr_code_scanner needs the constraints from the LayoutBuilder. |
Great :-)
|
Additional interesting link on a behaviour change from Android 12 which points how CameraX and Camera2 are impacting 3rd party apps differently on various devices https://developer.android.com/about/versions/12/features#camera2-extensions |
Thanks for your review @monsieurtanuki @teolemon I'm just going to merge so that we can test this scanner |
arf, merge conflict. |
Build faling because of jcenter server erros |
What
Now using ML Kit as default scanning engine (Default so that all testers even without knowing about the dev mode can test it)
Why
Caveats