RafaelBarbosatec / qr_code_dart_scan

A QR code scanner that works on both iOS and Android using dart decoder.
MIT License
14 stars 20 forks source link

After using Scan QR Code once and closing the Widget many messages I/CameraManagerGlobal(20308) keep being written to debug console. #12

Open longtimedeveloper opened 6 months ago

longtimedeveloper commented 6 months ago

After using Scan QR Code once and closing the Widget many messages keep appearing in the debug console. See example messages below the code.

I show this widget and then close it.

I am about to go live with the project, but am concerned about memory leaks.

When I navigate to this widget, I am not maintaining state. See navigation code below the widget.

Is there something I am not doing correctly? It seems strange that I keep getting these messages after closing this widget and navigating to other pages in the app.

Thank you for you assistance.

My Code

import 'package:flutter/material.dart';
import 'package:qr_code_dart_scan/qr_code_dart_scan.dart';
import 'package:spravzhni_shared/spravzhni_shared.dart';

class ScanQRCodeVew extends StatelessWidget {
  const ScanQRCodeVew({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(AppLocalization.instance.current.mobileScanQRCodeViewTitle), centerTitle: true),
      body: QRCodeDartScanView(
        typeScan: TypeScan.takePicture,
        scanInvertedQRCode: false,
        onCapture: (Result result) {
          Navigator.pop(context, result.text);
        },
      ),
    );
  }
}

Navigation Code

        await navigationKey.currentState!.pushReplacement(
          MaterialPageRoute(
            maintainState: false,
            builder: (_) => page,
          ),
        );

Debug Console Messages - they never stop, just keep being added to the console.

I/CameraManagerGlobal(20308): Camera 3 facing CAMERA_FACING_FRONT state now CAMERA_STATE_ACTIVE for client com.samsung.adaptivebrightnessgo API Level 2User Id 0 I/CameraManagerGlobal(20308): Camera 3 facing CAMERA_FACING_FRONT state now CAMERA_STATE_IDLE for client com.samsung.adaptivebrightnessgo API Level 2User Id 0 I/CameraManagerGlobal(20308): Camera 3 facing CAMERA_FACING_FRONT state now CAMERA_STATE_CLOSED for client com.samsung.adaptivebrightnessgo API Level 2User Id 0 I/CameraManagerGlobal(20308): Camera 3 facing CAMERA_FACING_FRONT state now CAMERA_STATE_OPEN for client com.samsung.adaptivebrightnessgo API Level 2User Id 0 I/CameraManagerGlobal(20308): Camera 3 facing CAMERA_FACING_FRONT state now CAMERA_STATE_ACTIVE for client com.samsung.adaptivebrightnessgo API Level 2User Id 0 I/CameraManagerGlobal(20308): Camera 3 facing CAMERA_FACING_FRONT state now CAMERA_STATE_IDLE for client com.samsung.adaptivebrightnessgo API Level 2User Id 0 I/CameraManagerGlobal(20308): Camera 3 facing CAMERA_FACING_FRONT state now CAMERA_STATE_CLOSED for client com.samsung.adaptivebrightnessgo API Level 2User Id 0 I/CameraManagerGlobal(20308): Camera 3 facing CAMERA_FACING_FRONT state now CAMERA_STATE_OPEN for client com.samsung.adaptivebrightnessgo API Level 2User Id 0 I/CameraManagerGlobal(20308): Camera 3 facing CAMERA_FACING_FRONT state now CAMERA_STATE_ACTIVE for client com.samsung.adaptivebrightnessgo API Level 2User Id 0 I/CameraManagerGlobal(20308): Camera 3 facing CAMERA_FACING_FRONT state now CAMERA_STATE_IDLE for client com.samsung.adaptivebrightnessgo API Level 2User Id 0 I/CameraManagerGlobal(20308): Camera 3 facing CAMERA_FACING_FRONT state now CAMERA_STATE_CLOSED for client com.samsung.adaptivebrightnessgo API Level 2User Id 0 I/CameraManagerGlobal(20308): Camera 3 facing CAMERA_FACING_FRONT state now CAMERA_STATE_OPEN for client com.samsung.adaptivebrightnessgo API Level 2User Id 0 I/CameraManagerGlobal(20308): Camera 3 facing CAMERA_FACING_FRONT state now CAMERA_STATE_ACTIVE for client com.samsung.adaptivebrightnessgo API Level 2User Id 0 I/CameraManagerGlobal(20308): Camera 3 facing CAMERA_FACING_FRONT state now CAMERA_STATE_IDLE for client com.samsung.adaptivebrightnessgo API Level 2User Id 0 I/CameraManagerGlobal(20308): Camera 3 facing CAMERA_FACING_FRONT state now CAMERA_STATE_CLOSED for client com.samsung.adaptivebrightnessgo API Level 2User Id 0

longtimedeveloper commented 6 months ago

@RafaelBarbosatec do you have any ideas or suggestions to correct this?

We want to go live with our application, but I have concerns, so at the moment so we are waiting for your thoughts before going live.

I am serving in Ukraine under terrible circumstances and need to go live. Thank you!

RafaelBarbosatec commented 6 months ago

Hi @longtimedeveloper ! I'm sorry for late. I will try take a look today.

RafaelBarbosatec commented 6 months ago

I'm sorry, I'm can’t reproduce this problem. I updated the dependencies, maybe it solve this problem. Version 0.7.4 available

longtimedeveloper commented 6 months ago

I'm sorry, I'm can’t reproduce this problem. I updated the dependencies, maybe it solve this problem. Version 0.7.4 available

I'll test now and let you know.

longtimedeveloper commented 6 months ago

@RafaelBarbosatec

example.zip I just updated the scan qr code code to the latest. I have attached your example app in the zip file.

When running the app on Android, I still get the same messages in the Debug Console after scanning the bar code. They continue being added.

longtimedeveloper commented 6 months ago

@RafaelBarbosatec my Flutter Doctor

Doctor output ```console flutter doctor -v [√] Flutter (Channel stable, 3.16.9, on Microsoft Windows [Version 10.0.19045.3930], locale en-US) • Flutter version 3.16.9 on channel stable at D:\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 41456452f2 (2 weeks ago), 2024-01-25 10:06:23 -0800 • Engine revision f40e976bed • Dart version 3.2.6 • DevTools version 2.28.5 [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 33.0.2) • Android SDK at C:\Users\Karl\AppData\Local\Android\sdk • Platform android-33-ext5, build-tools 33.0.2 • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-10027231) • All Android licenses accepted. [√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe [√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.8.1) • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community • Visual Studio Community 2022 version 17.8.34316.72 • Windows 10 SDK version 10.0.22000.0 [√] Android Studio (version 2022.3) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-10027231) [√] VS Code (version 1.85.1) • VS Code at C:\Users\Karl\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.82.0 [√] Connected device (4 available) • SM G780G (mobile) • RF8T10TP3CM • android-arm64 • Android 13 (API 33) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19045.3930] • Chrome (web) • chrome • web-javascript • Google Chrome 121.0.6167.140 • Edge (web) • edge • web-javascript • Microsoft Edge 121.0.2277.106 [√] Network resources • All expected network resources are available. • No issues found! ```
longtimedeveloper commented 6 months ago

@RafaelBarbosatec there are more dependencies that could be updated in the scan qr code package.

flutter pub outdated ```console D:\code\flutters\spikes\qr_code_dart_scan >flutter pub outdated Showing outdated packages. [*] indicates versions that are not the latest available. Package Name Current Upgradable Resolvable Latest direct dependencies: camera_platform_interface *2.5.0 2.7.3 2.7.3 2.7.3 zxing_lib *0.9.0 *0.9.0 1.1.2 1.1.2 dev_dependencies: flutter_lints *2.0.1 *2.0.3 3.0.1 3.0.1 2 upgradable dependencies are locked (in pubspec.lock) to older versions. To update these dependencies, use `flutter pub upgrade`. 2 dependencies are constrained to versions that are older than a resolvable version. To update these dependencies, edit pubspec.yaml, or run `flutter pub upgrade --major-versions`. D:\code\flutters\spikes\qr_code_dart_scan ```
longtimedeveloper commented 6 months ago

@RafaelBarbosatec maybe you can update these camera dependencies?

flutter pub get ```console >flutter pub get Resolving dependencies... camera_android 0.10.8+1 (0.10.8+16 available) camera_avfoundation 0.9.13+1 (0.9.14 available) camera_platform_interface 2.5.0 (2.7.3 available) camera_web 0.3.1+3 (0.3.2+4 available) charset 1.2.0 (2.0.1 available) cross_file 0.3.1+4 (0.3.3+8 available) flutter_lints 2.0.1 (3.0.1 available) flutter_plugin_android_lifecycle 2.0.3 (2.0.17 available) intl 0.18.1 (0.19.0 available) lints 2.0.1 (3.0.0 available) matcher 0.12.16 (0.12.16+1 available) material_color_utilities 0.5.0 (0.8.0 available) meta 1.10.0 (1.12.0 available) path 1.8.3 (1.9.0 available) petitparser 5.0.0 (6.0.2 available) plugin_platform_interface 2.1.2 (2.1.8 available) stream_transform 2.0.0 (2.1.0 available) test_api 0.6.1 (0.7.0 available) typed_data 1.3.0 (1.3.2 available) web 0.3.0 (0.4.2 available) xml 6.1.0 (6.5.0 available) zxing_lib 0.9.0 (1.1.2 available) Got dependencies! 22 packages have newer versions incompatible with dependency constraints. ```
RafaelBarbosatec commented 6 months ago

This dependencies don't have connections with this problem. For some reason in your test, when you navigate to other screen, the camera screen it's not disposed. Try do navitation.pop() with the qrcode when it's captureted instead of navigate to other screen.

longtimedeveloper commented 6 months ago

@RafaelBarbosatec I am using Navigator.pop(context, result) on Capture.

import 'package:flutter/material.dart';
import 'package:qr_code_dart_scan/qr_code_dart_scan.dart';

class LiveDecodePage extends StatefulWidget {
  const LiveDecodePage({Key? key}) : super(key: key);

  @override
  _LiveDecodePageState createState() => _LiveDecodePageState();
}

class _LiveDecodePageState extends State<LiveDecodePage> {
  Result? currentResult;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: QRCodeDartScanView(
        scanInvertedQRCode: false,
        onCapture: (Result result) {
          setState(() {
            Navigator.pop(context, result);
          });
        },
      ),
    );
  }
}

longtimedeveloper commented 6 months ago

@RafaelBarbosatec I just tried using a StatelessWidget and not passing the Result object back, instead pass the string in the Navigator.pop(). Still have the same issues with the messages continuing in the Debug Console.

import 'package:flutter/material.dart';
import 'package:qr_code_dart_scan/qr_code_dart_scan.dart';

class LiveDecodePage extends StatelessWidget {
  const LiveDecodePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: QRCodeDartScanView(
        scanInvertedQRCode: false,
        onCapture: (Result result) {
          var resultText = '';
          resultText = result.text;
          Navigator.pop(context, resultText);
        },
      ),
    );
  }
}

longtimedeveloper commented 6 months ago

@RafaelBarbosatec any progress?

RafaelBarbosatec commented 6 months ago

Hi @longtimedeveloper! I don't know why this problem persist in your device. I can't reproduce it. anyway I will be adding the methos dispose in QRCodeDartScanController to you try do dispose manually.

longtimedeveloper commented 6 months ago

@RafaelBarbosatec I have stepped through the code when Navigator.pop(context, resultText); is invoked. Your QRCodeDartScanView widget's dispose method is invoked.

RafaelBarbosatec commented 6 months ago

Maybe could be a 'camera' plugin bug in some devices. I already try it on Xiaomi k20 and a Samsung and work well.

longtimedeveloper commented 6 months ago

@RafaelBarbosatec my apartment here in Kherson, Ukraine was hit on Saturday. I am OK. Thankfully no one was injured or killed because most apartments are vacant. My internet has been down since the strike because the cables were blown off the building.

I once I have internet, I'll write a small app that uses the camera plugins you are using and see if I still have the same problems and will let you know. Hopefully my internet will get fixed very soon.

Thank you for trying and helping.

RafaelBarbosatec commented 6 months ago

Hi @longtimedeveloper ! 😳 How horrible, I hope you and your family are well! Thanks so much for your reporting. In parallel I'm take a look in this case in my free time. Anything I'll notify you!

longtimedeveloper commented 6 months ago

@RafaelBarbosatec My internet was restored this morning. :-)

I created an Android app using the same Camera Plugin Scan QR code uses. I did not have the same messages in the debug console.

I spent an hour debugging and trying different code techniques to get the Scan QR Code example to not continue to add the reported messages to the debug console. I was unsuccessful.

Maybe you'll have better luck than I did. Thank you for trying.

This is a build warning I get. This warning was covered in this Flutter Release Note. If you have time, maybe you can update the Example app for future Flutter developers using the package.

''' You are applying Flutter's app_plugin_loader Gradle plugin imperatively using the apply script method, which is deprecated and will be removed in a future release. Migrate to applying Gradle plugins with the declarative plugins block: https://flutter.dev/go/flutter-gradle-plugin-apply

You are applying Flutter's main Gradle plugin imperatively using the apply script method, which is deprecated and will be removed in a future release. Migrate to applying Gradle plugins with the declarative plugins block: https://flutter.dev/go/flutter-gradle-plugin-apply '''

RafaelBarbosatec commented 6 months ago

Hi @longtimedeveloper ! In the develop branch I updated the android example. It's crazy, but I don't reproduce this problem in my device yet.

longtimedeveloper commented 6 months ago

@RafaelBarbosatec thank you for trying. I'll let my team know to close the app after they use it. This way we won't have any possible negative side effects. When I get more time, I'll try to write a version of Scan QR code that does what I need. If I can get it to work without the messages, I'll send you a link to the app for to look at. Maybe it could help? Maybe I am the only one with this issue? Next week, I have someone coming with an iOS device. We will run it in debug mode and see if we get the same results.

Best to you, and thanks again for a great QR Code Scanner.

RafaelBarbosatec commented 6 months ago

Thank's @longtimedeveloper ! Perfect, I stay waiting. This appears to be a problem on Samsung devices. I use this package in my job and we don't have this problem. It's really strange. Any news or solution I find. I will be adding it to the package.