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
756 stars 446 forks source link

scan window not WORKING.. #959

Open Mohammed3194 opened 3 months ago

Mohammed3194 commented 3 months ago

Hi @juliansteenbakker, @navaronbracke, @EArminjon, @hazzo,

I am using mobile_scanner plugin v3.5.2, to scan the data matrix QR code. Everything works so well thanks you everyone. But, i am facing on issue, may be i would say it is a blocker for me. When i apply a scanWindow for MobileScanner, QR code is not at all scanning. When comment out the scanWindow scanner works well..

image

I am not understanding what is going wrong, please help me fixing this issue.. Any help out be appreciated.

cc: @MBulli @woolfred @ryanduffyne @vbuberen @jlin5

EArminjon commented 3 months ago

Hello,

Scaffold apply some margins / paddings and also can contain an AppBar. I suggest first of all to not use the context of MediaQuery but the closest context near MobileScanner.

Wrap your MobileScanner with a LayoutBuilder() and then use this context to compute the size of your scanWindow.

I didn't know if it will fix your issue but anyway, it will help.

navaronbracke commented 3 months ago

Thank you for the report. Does the example app sample with the scan window work for you? If that one does work, then, as stated above, I suggest checking which BuildContext you use to determine the scan window.

Also, I would advise not to tag everyone on this issue, as to not distract people with notifications and such.

Mohammed3194 commented 3 months ago

Hello,

Scaffold apply some margins / paddings and also can contain an AppBar. I suggest first of all to not use the context of MediaQuery but the closest context near MobileScanner.

Wrap your MobileScanner with a LayoutBuilder() and then use this context to compute the size of your scanWindow.

I didn't know if it will fix your issue but anyway, it will help.

@EArminjon - I did wrap the MobileScanner with LayoutBuilder() and used builder context. But, still the same, QR is not picking up :(

Updated Code:

image
Mohammed3194 commented 3 months ago

Thank you for the report. Does the example app sample with the scan window work for you? If that one does work, then, as stated above, I suggest checking which BuildContext you use to determine the scan window.

Also, I would advise not to tag everyone on this issue, as to not distract people with notifications and such.

@navaronbracke - Sorry, for tagging everyone. Yes, the example app sample works fine with scan windows.

EArminjon commented 3 months ago

Try constraints instead of MediaQuery ?

Shakle commented 3 months ago

Also stopped working when enabling impeller on android, without works

navaronbracke commented 3 months ago

@Shakle Impeller on Android is still in preview, so issues with the Texture registry are expected at this point (hence it's a preview)

Mohammed3194 commented 3 months ago

Try constraints instead of MediaQuery ?

@EArminjon Yes, tried no luck..

Sorry, I missed you mentioned you that MobileScanner is wrapped inside the FutureBuilder. Where FutureBuilder is the parent widget and MobileScanner is the Nested widget.

Does this make any difference ?

cc: @navaronbracke

navaronbracke commented 3 months ago

That should not make any difference, in that case just use the BuildContext of the FutureBuilder ?

Mohammed3194 commented 3 months ago

That should not make any difference, in that case just use the BuildContext of the FutureBuilder ?

Not working :( :(

navaronbracke commented 3 months ago

What is the rectangle value for your scan window? Maybe it is in the wrong position?

MBulli commented 3 months ago

Can you post a complete minimal working example? Starting from the main() function, including only the relevant widgets to reproduce the problem?

Mohammed3194 commented 3 months ago

Can you post a complete minimal working example? Starting from the main() function, including only the relevant widgets to reproduce the problem?

Sure, will share..

navaronbracke commented 2 months ago

@Mohammed3194 Can you test version 5.0.0-beta.2 ? I made a bugfix for the scan window, which was not updated when the rectangle itself changed dimensions.

burekas7 commented 1 month ago

@navaronbracke

I have problem with the scanWidow too.

I'm trying to use the beta version: 5.0.0-beta.2

But these function doesn't exist (MobileScanner constructor):

Do you have any docs about it?

navaronbracke commented 1 month ago

Instead of using onDetect, listen to the Stream<BarcodeCapture> that is provided by the controller. Since you now manually start the controller, onScannerStarted no longer exists. Instead do the following:

await controller.start();
// set the zoom scale after the controller started
burekas7 commented 1 month ago

@navaronbracke

Regarding the bug. It seems that it ignores the "center" value, or maybe the whole scanWindow (I modified the Offsets value)

(Using 5.0.0 beta)

navaronbracke commented 1 month ago

What do you mean by that? The scanWindow is a rectangle that is relative to the camera output.

If I understand correctly, if scanWindow is set, a barcode must have its points inside that rectangle.

burekas7 commented 1 month ago

@navaronbracke

I took this from your example:

    final scanWindow = Rect.fromCenter(
      center: MediaQuery.sizeOf(context).center(Offset.zero),
      width: 200,
      height: 200,
    );

But when I change the Offset it still read from the same area as Offset.zero.

burekas7 commented 1 month ago

@navaronbracke

Update: It's working :)

navaronbracke commented 1 month ago

Just so I understand, what was the problem you were facing with the offset?

burekas7 commented 1 month ago

@navaronbracke I implement the "Target" for scanning with another class (It's not just a transparent window as you did) So I was need to debug where exactly is the center, and then I fix the offset for the Mobile Scanner.

By the way, your "Target" in your example is not good, the window is showing at the bottom-right of the screen and very very small.