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
[BUG] Camera zoom in iOS vs Android #250
Comments
I have the same issue on my iPhone 11 Pro (iOS v.14.0.1). The QR code scanner starts with a magnified zoom (comparing to the iPhone camera it looks like 4x). It happens in both debug and production. Quite critical, as sometimes it does not even read any QR code in the cutout square, but it reads the code if it is below and outside the square. |
It appears that if I do not provide an I am talking about this function:
When I tried to set both |
I have updated the iOS code in the following branch: camera-facing-not-correct-ios. Can you please try that branch and check if it resolves this issue? I have tested it with an iPad Air 2 running iOS 14.4 and an iPhone 5S running iOS 12.5.1 and i couldn't reproduce this bug anymore. |
I did try your branch now given the following
Sadly I still experience the same issue. Thanks for giving it priority though! |
I have tried manually setting some values for |
The fact that the camerapreview expands behind the buttons is due to |
info flutter doctor -v: [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2) ! Doctor found issues in 1 category. [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2) [✓] Xcode - develop for iOS and macOS (Xcode 12.2) [!] Android Studio (version 4.1) [✓] VS Code (version 1.52.1) [✓] Connected device (1 available) ! Doctor found issues in 1 category. p/s I don't have this problem on lower version (qr_code_scanner 0.3.2) |
If you turn your screen and it changes orientation, does the camerapreview change size? |
I test every way, it still zoom in |
Which iPhone are you using? |
Also, what happens if you switch to the front camera? |
I use iPhone XS Max and xiaomi redmi 5 (Android) |
I also tried both front and back camera, which have the same problem |
Okay, so it's not using the physical zoom lens which the iPhone XS Max has. I will try it tonight with an iPhone 11. @thomaaam Do you also encounter this issue on the camera-facing-not-correct-ios branch example app? |
When I cloned the repository, moved to Here is
|
I experience the exact same behaviour with our app. However note that it resets (on app resume) to 2x, not to 1x, starting at 4x initially. |
Okay so i think i know what the problem is. On the first run, the following piece of code is not executed on some devices. This piece of code handles the size of the preview. When this is not set, it will crop a 16:9 image to fit a portrait screen. This is why everything seems zoomed in.
I'm gonna try some other methods of initiating this and will post an update as soon as i have found a solution. |
After some testing with an iPhone 11 I've found that adding a small delay to the initial call of |
One thing i noticed is that on iOS there always is a little zoomfactor. This is something set by the underlying framework. On my iPad mini its more like 1.4x zoom rather than 2x or 4x and on a iPhone 11 its 1.3x zoom. |
I updated the package and tried again for both the example app and our app. For our app it seemed to work on first init, but all the subsequent attempts failed, again seeing the zoom on init. For the example app nothing changed for me 😞 |
Did these problems started with version 0.3.2, or did you also encounter this problem with previous versions? (0.3.1, 0.3.0) |
The last time I can guarantee that it worked was v0.0.14. I can do some experiments and find out which previous version that was most promising regarding this specific issue. |
Can you provide some example code? It would be a lot easier to fix this bug if i can reproduce this bug. |
OK, my test code looks like this:
DetailTest.dart
|
Thank you for providing the code. Now i'm able to reproduce the bug. So there are a couple of things going wrong here. For starters, in your The second issue is that you are using Navigator.push instead of Navigator.pop. I guess you did this because you couldn't go back to the qrview because it opened many new pages. If you use push, you're opening a new page, and the page tree will get very dirty. //Navigator.of(context).pop();
Navigator.push(
context,
MaterialPageRoute(builder: (context) => QRViewExample()),
); The third issue is when opening the QRView with Navigator.push it opens it with the 4x zoom. This is indeed a bug and i am working on a fix for this. The last issue is that when you pause the camera before opening the second screen and you call navigator.pop, it returns to the first qrview however it's paused. This can be solved by adding a return value to the navigator.pop(), so that we can check when that value is returned and resume the camera. I made an example using @luanssd example code. main.dart var qrViewOpened = false;
Future<void> _onQRViewCreated(QRViewController controller) async {
setState(() {
this.controller = controller;
});
controller.scannedDataStream.listen((scanData) async {
await controller.pauseCamera();
if (!qrViewOpened) {
qrViewOpened = true;
var secondScreen = await Navigator.push(
context,
MaterialPageRoute(builder: (context) => DetailTest(result: scanData.code)));
if (secondScreen) {
qrViewOpened = false;
await controller.resumeCamera();
}
}
});
} detail_test.dart import 'package:flutter/material.dart';
class DetailTest extends StatefulWidget {
const DetailTest({
Key key,
this.result,
}) : super(key: key);
final result;
@override
State<StatefulWidget> createState() => DetailTestPage();
}
class DetailTestPage extends State<DetailTest> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 0.3,
centerTitle: true,
leading: GestureDetector(
onTap: () => Navigator.of(context).pop(true),
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 20,
),
child: CircleAvatar(
backgroundColor: Colors.transparent,
radius: 14,
child: Icon(
Icons.arrow_back_ios,
color: Colors.white,
size: 28,
),
),
),
),
title: Text("DetailTestPage"),
actions: <Widget>[],
),
body: Container(
alignment: Alignment.center,
margin: EdgeInsets.only(top: 20, left: 0, right: 0),
child: Column(children: <Widget>[
Center(
child: Text('Detail result'),
),
Container(
child: Text('${widget.result}'),
),
])));
}
} |
After some research i found out that this is caused due to the renderbox in updateDimensions not being loaded correctly. I fixed this by adding a small delay to it. The changes are now on the master branch. Can someone verify if the bug is gone? |
I'm sorry, I provided the code just for simulation. main.dart
home.dart
scan.dart
detail.dart
|
@luanssd if you change |
also does not improve, you try the new code I sent the full view, when switching tabs. |
Hi! |
Hi @juliansteenbakker , when can the new version 0.3.5 be released? thanks! |
Just released v0.3.5. Thank you all for your patience. |
I have updated and the results are as expected. Thank you @juliansteenbakker for everything you have brought! |
@juliansteenbakker this issue still happens sometimes, rarely, but...i don't think delay made the trick. using 0.4.0 |
We are having this issue every time we install a new build. (Update or clean install) After that we never have this issue again. We are using 0.4.0 |
If we send our app to the background and come back we see the same effect as @luanssd stated here
@juliansteenbakker do you have any other options that we can try? |
So i just encountered this issue myself yesterday. While i am trying some other things to get this bug fixed, im really more focussed on bringing more options to the new MLKit framework because the QRView framework is deprecated. I'll post an update as soon as i have a fix for this. |
This is currently a blocking issue with the highest prio for our app. If you want we can setup a call tomorrow so you can inform me on what you already tried. Otherwise I will be taking a look at this tomorrow and start from scratch trying to find our where this issue is located. |
First thing in the morning i'm gonna try to see if the problem is related to the render box still not being loaded when static Future<bool> updateDimensions(GlobalKey key, MethodChannel channel,
{QrScannerOverlayShape? overlay}) async {
if (defaultTargetPlatform == TargetPlatform.iOS) {
// Add small delay to ensure the render box is loaded
await Future.delayed(Duration(milliseconds: 100)); // Try and change to 300? |
So i tried it with 300 miliseconds delay and i wasn't able to reproduce this behavior anymore. Can you check if that also helps for you @vanlooverenkoen? |
Yes did the same thing https://github.com/vanlooverenkoen/qr_code_scanner/tree/bugfix/%23250-zoomed-ios-camera |
Looking good. We will do some extra testing. And use this fix in production. |
We did extra tests and could not find any more problems. We will release with my fork for now. (Our app is submitted for review). I will let you know when we see the user feedback about this issue going down or not. For your information our app has 50k users: 33k iOS and 17k Android. |
Nice to hear! If you could make a pull request i'm happy to merge it. |
Perfect I will do that in the next couple of hours. |
…amera Bugfix/#250 zoomed ios camera
I just updated to the latest version qr_code_scanner 0.3.2, and found that the camera is magnified (zoom in iOS vs Android), I want to adjust the normal zoom mode
The text was updated successfully, but these errors were encountered: