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

[BUG] Camera zoom in iOS vs Android #250

Closed
luanssd opened this issue Feb 6, 2021 · 60 comments · Fixed by #371
Closed

[BUG] Camera zoom in iOS vs Android #250

luanssd opened this issue Feb 6, 2021 · 60 comments · Fixed by #371
Labels
bug Something isn't working question Further information is requested
Milestone

Comments

@luanssd
Copy link

luanssd commented Feb 6, 2021

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

@luanssd luanssd added the bug Something isn't working label Feb 6, 2021
@thomaaam
Copy link

thomaaam commented Feb 7, 2021

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.

@thomaaam
Copy link

thomaaam commented Feb 7, 2021

It appears that if I do not provide an overlay argument to the QRView widget, then it (mostly) starts without a zoom.
Now I am just speculating, but can there be a bug with the scanArea and/or scanAreaOffset functionality?
I noticed that QRView's overlay argument affects these values, and the scanArea functionality was added in version v.0.2.0, whereas version 0.0.14 has always worked for us on both platforms.

I am talking about this function:

/// Updates the view dimensions for iOS.
static Future<void> updateDimensions(GlobalKey key, MethodChannel channel,
    {QrScannerOverlayShape overlay}) async {
  if (defaultTargetPlatform == TargetPlatform.iOS) {
    final RenderBox renderBox = key.currentContext.findRenderObject();
    try {
      await channel.invokeMethod('setDimensions', {
        'width': renderBox.size.width,
        'height': renderBox.size.height,
        'scanArea': overlay?.cutOutSize ?? 0,
        'scanAreaOffset': overlay?.cutOutBottomOffset ?? 0
      });
    } on PlatformException catch (e) {
      throw CameraException(e.code, e.message);
    }
  }
}

When I tried to set both scanArea and scanAreaOffset to 0 here, it worked as if I would not provide an overlay argument, however the the QR code scanner successfully scanned a QR code outside the scan area, so it does not really fix the problem.

@juliansteenbakker
Copy link
Collaborator

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.

@juliansteenbakker juliansteenbakker added the question Further information is requested label Feb 8, 2021
@thomaaam
Copy link

thomaaam commented Feb 8, 2021

I did try your branch now given the following pubspec.yaml setup:

qr_code_scanner:
  git:
    url: git://github.com/juliuscanute/qr_code_scanner.git
    ref: camera-facing-not-correct-ios

Sadly I still experience the same issue.

Thanks for giving it priority though!

@juliansteenbakker
Copy link
Collaborator

I have tried manually setting some values for scanArea and scanAreaOffset and in all cases everything works just fine here. Can you try the example app provided in the camera-facing-not-correct-ios branch? Thats the one i use to test this.

@luanssd
Copy link
Author

luanssd commented Feb 8, 2021

I installed the test in the branch, the results still have not improved

Normal camera zoom
IMG_0303

Camear zoom size is about 4x
IMG_0302

@juliansteenbakker
Copy link
Collaborator

The fact that the camerapreview expands behind the buttons is due to updateDimensions not being called. I can't figure out why this is happening since it is working on every device i try it with. @luanssd which iPhone and iOS version are you using? Also, can you provide the output of flutter doctor -v?

@luanssd
Copy link
Author

luanssd commented Feb 8, 2021

info flutter doctor -v:
MacBook-Pro:MyApp Macbook$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.6, on Mac OS X 10.15.7 19H2 darwin-x64, locale en-VN)

[✓] 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)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.52.1)
[✓] Connected device (1 available)

! Doctor found issues in 1 category.
MacBook-Pro:MyApp Macbook$ flutter doctor -v
[✓] Flutter (Channel stable, 1.22.6, on Mac OS X 10.15.7 19H2 darwin-x64, locale en-VN)
• Flutter version 1.22.6 at /Users/Macbook/Developer/flutter
• Framework revision 9b2d32b605 (2 weeks ago), 2021-01-22 14:36:39 -0800
• Engine revision 2f0af37152
• Dart version 2.10.5

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/Macbook/Library/Android/sdk
• Platform android-30, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.2, Build version 12B45b
• CocoaPods version 1.8.4

[!] Android Studio (version 4.1)
• Android Studio at /Applications/Android Studio.app/Contents
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[✓] VS Code (version 1.52.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.16.0

[✓] Connected device (1 available)
• iPhone (mobile) • 00008020-000218923E28002E • ios • iOS 13.3

! Doctor found issues in 1 category.

p/s I don't have this problem on lower version (qr_code_scanner 0.3.2)

@juliansteenbakker
Copy link
Collaborator

If you turn your screen and it changes orientation, does the camerapreview change size?

@luanssd
Copy link
Author

luanssd commented Feb 8, 2021

I test every way, it still zoom in

@juliansteenbakker
Copy link
Collaborator

Which iPhone are you using?

@juliansteenbakker
Copy link
Collaborator

Also, what happens if you switch to the front camera?

@luanssd
Copy link
Author

luanssd commented Feb 8, 2021

I use iPhone XS Max and xiaomi redmi 5 (Android)

@luanssd
Copy link
Author

luanssd commented Feb 8, 2021

Also, what happens if you switch to the front camera?

I also tried both front and back camera, which have the same problem

@juliansteenbakker
Copy link
Collaborator

juliansteenbakker commented Feb 8, 2021

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?

@thomaaam
Copy link

thomaaam commented Feb 8, 2021

@juliansteenbakker:

When I cloned the repository, moved to camera-facing-not-correct-ios, opened the example folder in Xcode and run the project, I experienced the same issue. However (!), interestingly, if I opened the app drawer and selected the running app, it resets its camera and the zoom level worked as expected. Maybe there are some race conditions that invoke updateDimensions before it should be invoked, updating the zoom prematurely.

Here is flutter doctor --verbose for the example project:

[✓] Flutter (Channel stable, 1.22.6, on macOS 11.1 20C69 darwin-x64, locale en-NO)
    • Flutter version 1.22.6 at /Users/thomaaam/flutter
    • Framework revision 9b2d32b605 (2 weeks ago), 2021-01-22 14:36:39 -0800
    • Engine revision 2f0af37152
    • Dart version 2.10.5

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/thomaaam/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.4, Build version 12D4e
    • CocoaPods version 1.10.0

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin installed
    • Dart plugin version 201.9317
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[✓] Connected device (1 available)
    • Gullgrotta (mobile) • 00008030-00092DA00E04802E • ios • iOS 14.0.1

• No issues found!

@thomaaam
Copy link

thomaaam commented Feb 8, 2021

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.

@juliansteenbakker
Copy link
Collaborator

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.

       // Set the size of the preview.
        if let previewLayer = self.scanner?.previewLayer {
            previewLayer.frame = self.previewView.bounds;
        }

I'm gonna try some other methods of initiating this and will post an update as soon as i have found a solution.

@juliansteenbakker
Copy link
Collaborator

After some testing with an iPhone 11 I've found that adding a small delay to the initial call of updateDimensions function, and adding a nullcheck on the LifecycleEventHandler fixes the issue. Can you please check again?

@juliansteenbakker
Copy link
Collaborator

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.

@thomaaam
Copy link

thomaaam commented Feb 8, 2021

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 😞

@juliansteenbakker
Copy link
Collaborator

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)

@thomaaam
Copy link

thomaaam commented Feb 8, 2021

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.

@juliansteenbakker
Copy link
Collaborator

I try version 0.3.3 on my iphone:
Opening it the first time is fine, when switching to another screen and then returning to scan mode, the zoom error is repeated.

Can you provide some example code? It would be a lot easier to fix this bug if i can reproduce this bug.

@luanssd
Copy link
Author

luanssd commented Feb 11, 2021

OK, my test code looks like this:

void _onQRViewCreated(QRViewController controller) {
  setState(() {
    this.controller = controller;
  });
  controller.scannedDataStream.listen((scanData) {
    if(scanData.code != null)
      {
        Navigator.push(
          context,
          MaterialPageRoute(builder: (context) => DetailTest(result: scanData.code)),
        );
      }
  });
}

DetailTest.dart

import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:mypackage/scan.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 new Scaffold(
      appBar: new AppBar(
        elevation: 0.3,
        centerTitle: true,
        //backgroundColor: AppDefalut(),
        leading: GestureDetector(
          onTap: () {

            //Navigator.of(context).pop();
            Navigator.push(
              context,
              MaterialPageRoute(builder: (context) => QRViewExample()),
            );
          },
          child: Padding(
            padding: EdgeInsets.symmetric(horizontal: 20,),
            child: new CircleAvatar(
              backgroundColor: Colors.transparent,
              radius: 14.0,
              child: new Icon(
                Icons.arrow_back_ios,
                color: Colors.white,
                size: 28.0,
              ),
            ),
          ),
        ),
        title: new Text("DetailTestPage"),
        actions: <Widget>[

        ],
      ),
      body: new Container(
          alignment: Alignment.center,
          margin: EdgeInsets.only(top: 20, left: 0, right: 0),
          child: new Column(
              children: <Widget>[
                new Center(
                  child:  Text('Detail result'),
                ),
                new Container(
                  child:  Text('${widget.result}'),
                ),
              ]
          )
      ) 
    );
  }

}


@juliansteenbakker
Copy link
Collaborator

juliansteenbakker commented Feb 11, 2021

OK, my test code looks like this:

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 scannedDataStream you don't pause or stop the cameraview so it keeps pushing the second screen which is causing immense performance issues. It also keeps detecting QRCodes while the second screen is open.

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
Note: onTap: () => Navigator.of(context).pop(true),

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}'),
              ),
            ])));
  }
}

@juliansteenbakker
Copy link
Collaborator

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.

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?

@luanssd
Copy link
Author

luanssd commented Feb 11, 2021

I'm sorry, I provided the code just for simulation.
In fact, my app integrates pageview form back and forth between screens and tabs.
I send these codes for you to test:

main.dart

void main() 
{
  runApp(
    new MaterialApp(home: new MyApp()),
  );
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
  int ontab = 1;

@override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: DefaultTabController(
        length: 3,
        initialIndex: ontab,
        child: Scaffold(
          appBar: AppBar(
            bottom: TabBar(
              tabs: [
                Tab(text: 'Home'),
                Tab(text: 'SCAN',),
                Tab(text: 'Detail'),
              ],
            ),
            title: Text('TABS TITLE TEXT'),
          ),
          body: TabBarView(
            children: [
              Homepage(),
              QRViewExample(),
              DetailTest()
            ],
          ),
        ),
      ),
    );
  }
}

home.dart

class Homepage extends StatefulWidget
{
  const Homepage({
    Key key,
  }) : super(key: key);

  @override
  State<StatefulWidget> createState() => HomepageTestPage();
}

class HomepageTestPage extends State<Homepage>
{

  @override
  Widget build(BuildContext context)
  {

    return new Scaffold(

      body: new Container(
          alignment: Alignment.center,
          margin: EdgeInsets.only(top: 20, left: 0, right: 0),
          child: new Column(
              children: <Widget>[
                new Center(
                  child:  Text('Home page'),
                ),
                new Container(
                  child:  Text(''),
                ),
              ]
          )
      ) 
    );
  } 
}

scan.dart

class QRViewExample extends StatefulWidget {
  const QRViewExample({
    Key key,
  }) : super(key: key);

  @override
  State<StatefulWidget> createState() => _QRViewExampleState();
}


class _QRViewExampleState extends State<QRViewExample> {
  Barcode result;
  QRViewController controller;
  final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');

  // In order to get hot reload to work we need to pause the camera if the platform
  // is android, or resume the camera if the platform is iOS.
  @override
  void reassemble() {
    super.reassemble();
    if (Platform.isAndroid) {
      controller.pauseCamera();
    } else if (Platform.isIOS) {
      controller.resumeCamera();
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: <Widget>[
          Expanded(flex: 4, child: _buildQrView(context)),
          Expanded(
            flex: 1,
            child: FittedBox(
              fit: BoxFit.contain,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[
                  if (result != null)
                    Text(
                        'Barcode Type: ${describeEnum(result.format)}   Data: ${result.code}')
                  else
                    Text('Scan a code'),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      Container(
                        margin: EdgeInsets.all(8),
                        child: ElevatedButton(
                            onPressed: () async {
                              await controller?.toggleFlash();
                              setState(() {});
                            },
                            child: FutureBuilder(
                              future: controller?.getFlashStatus(),
                              builder: (context, snapshot) {
                                return Text('Flash: ${snapshot.data}');
                              },
                            )),
                      ),
                      Container(
                        margin: EdgeInsets.all(8),
                        child: ElevatedButton(
                            onPressed: () async {
                              await controller?.flipCamera();
                              setState(() {});
                            },
                            child: FutureBuilder(
                              future: controller?.getCameraInfo(),
                              builder: (context, snapshot) {
                                if (snapshot.data != null) {
                                  return Text(
                                      'Camera facing ${describeEnum(snapshot.data)}');
                                } else {
                                  return Text('loading');
                                }
                              },
                            )),
                      )
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      Container(
                        margin: EdgeInsets.all(8),
                        child: ElevatedButton(
                          onPressed: () async {
                            await controller?.pauseCamera();
                          },
                          child: Text('pause', style: TextStyle(fontSize: 20)),
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.all(8),
                        child: ElevatedButton(
                          onPressed: () async {
                            await controller?.resumeCamera();
                          },
                          child: Text('resume', style: TextStyle(fontSize: 20)),
                        ),
                      )
                    ],
                  ),
                ],
              ),
            ),
          )
        ],
      ),
    );
  }

  Widget _buildQrView(BuildContext context) {
    // For this example we check how width or tall the device is and change the scanArea and overlay accordingly.
    if(result != null)
    {
      controller?.pauseCamera();
      var detail_value = result.code;
      WidgetsBinding.instance.addPostFrameCallback((_) async {
        //Navigator.of(context).pushNamed("/detail");
      });
      setState(()
      {
        result = null;
      });
    }
    var scanArea = (MediaQuery.of(context).size.width < 400 ||
        MediaQuery.of(context).size.height < 400)
        ? 150.0
        : 300.0;
    // To ensure the Scanner view is properly sizes after rotation
    // we need to listen for Flutter SizeChanged notification and update controller
    return QRView(
      key: qrKey,
      onQRViewCreated: _onQRViewCreated,
      overlay: QrScannerOverlayShape(
          borderColor: Colors.red,
          borderRadius: 10,
          borderLength: 30,
          borderWidth: 10,
          cutOutSize: scanArea),
    );
  }

  void _onQRViewCreated(QRViewController controller) {
    setState(() {
      this.controller = controller;
    });
    controller.scannedDataStream.listen((scanData) {
      setState(() {
        result = scanData;
      });
    });
  }

  @override
  void dispose() {
    controller?.dispose();
    super.dispose();
  }
}

detail.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 new Scaffold( 
      body: new Container(
          alignment: Alignment.center,
          margin: EdgeInsets.only(top: 20, left: 0, right: 0),
          child: new Column(
              children: <Widget>[
                new Center(
                  child:  Text('Detail result'),
                ),
                new Container(
                  child:  Text('${widget.result}'),
                ),
              ]
          )
      ) 
    );
  } 
}

@juliansteenbakker
Copy link
Collaborator

@luanssd if you change _onQRViewCreated to the one i commented just now it should work. I am working on version 0.3.5 to be released with the fix that is now on the master branch.

@luanssd
Copy link
Author

luanssd commented Feb 11, 2021

also does not improve, you try the new code I sent the full view, when switching tabs.
You watch this video to check: https://youtu.be/lVrsRSF_8eQ
But strangely at the end of the video it was back in an acceptable state.

@njustin
Copy link

njustin commented Feb 13, 2021

Hi!
We just had the same issue: when the QRView was loaded the second time, the image was zoomed (likely 4x) and the view also covered a part of our layout.
I have just tested the master, and the issue seems to be solved for us.
Thanks !

@xmany
Copy link

xmany commented Feb 18, 2021

Hi @juliansteenbakker , when can the new version 0.3.5 be released? thanks!

@juliansteenbakker
Copy link
Collaborator

Just released v0.3.5. Thank you all for your patience.

@luanssd
Copy link
Author

luanssd commented Feb 20, 2021

I have updated and the results are as expected. Thank you @juliansteenbakker for everything you have brought!

@qqmikey
Copy link

qqmikey commented May 7, 2021

@juliansteenbakker this issue still happens sometimes, rarely, but...i don't think delay made the trick. using 0.4.0

@vanlooverenkoen
Copy link
Contributor

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

@vanlooverenkoen
Copy link
Contributor

vanlooverenkoen commented Jul 14, 2021

If we send our app to the background and come back we see the same effect as @luanssd stated here

also does not improve, you try the new code I sent the full view, when switching tabs.
You watch this video to check: https://youtu.be/lVrsRSF_8eQ
But strangely at the end of the video it was back in an acceptable state.

@juliansteenbakker do you have any other options that we can try?

@juliansteenbakker
Copy link
Collaborator

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.

@vanlooverenkoen
Copy link
Contributor

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.

@juliansteenbakker
Copy link
Collaborator

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 updateDimensions is being called. The original fix was a small delay before calling setDimensions because the renderbox of the QRView was not yet fully loaded. It would be logical if that delay was to short and thus sometimes the renderbox is not yet fully loaded. It's still kind of a hacky way to deal with the problem however with the focus on the new framework i think we can safely try to increase the delay a bit and see if that resolves the problem.

 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?

@juliansteenbakker
Copy link
Collaborator

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?

@vanlooverenkoen
Copy link
Contributor

Yes did the same thing https://github.com/vanlooverenkoen/qr_code_scanner/tree/bugfix/%23250-zoomed-ios-camera
And I will now create new production build. Send it to my clients who had this issue every time after a clean install. I will keep you posted. But that seems to be doing the trick indeed.

@vanlooverenkoen
Copy link
Contributor

Looking good. We will do some extra testing. And use this fix in production.

@vanlooverenkoen
Copy link
Contributor

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.

@juliansteenbakker
Copy link
Collaborator

Nice to hear! If you could make a pull request i'm happy to merge it.

@vanlooverenkoen
Copy link
Contributor

Perfect I will do that in the next couple of hours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants