khoren93 / flutter_zxing

Flutter plugin for scanning and generating QR codes using the ZXing library, supporting Android, iOS, and desktop platforms
https://pub.dev/packages/flutter_zxing
MIT License
98 stars 56 forks source link

onControllerCreated callback is sometimes not called in v1.1.1 #88

Closed kaboc closed 1 year ago

kaboc commented 1 year ago

The example app below shows a MaterialBanner when the callback of onControllerCreated is called. As you can see, it is not shown once in several times. I didn't see this issue when I was using 1.0.0.

Code ```dart import 'package:flutter/material.dart'; import 'package:flutter_zxing/flutter_zxing.dart'; void main() => runApp(const App()); class App extends StatefulWidget { const App({super.key}); @override State createState() => _AppState(); } class _AppState extends State { final _pageController = PageController(); int _page = 0; @override Widget build(BuildContext context) { return MaterialApp( scaffoldMessengerKey: scaffoldMessengerKey, home: Scaffold( body: PageView( controller: _pageController, onPageChanged: _switchPage, children: const [ _ScanView(), _SecondView(), ], ), bottomNavigationBar: BottomNavigationBar( currentIndex: _page, onTap: _switchPage, items: const [ BottomNavigationBarItem( icon: Icon(Icons.photo_camera), label: 'Page 1', ), BottomNavigationBarItem( icon: Icon(Icons.star), label: 'Page 2', ), ], ), ), ); } void _switchPage(int page) { setState(() => _page = page); _pageController.jumpToPage(page); if (page == 1) { _hideMaterialBanner(); } } } class _ScanView extends StatelessWidget { const _ScanView(); @override Widget build(BuildContext context) { return ReaderWidget( onControllerCreated: (_) => _showMaterialBanner(), onScan: (code) => print(code.text), ); } } class _SecondView extends StatelessWidget { const _SecondView(); @override Widget build(BuildContext context) { return const Center( child: Text('Page 2'), ); } } //=================================================================== final scaffoldMessengerKey = GlobalKey(); void _showMaterialBanner() { scaffoldMessengerKey.currentState!.showMaterialBanner( MaterialBanner( content: const Text('Controller was created.'), actions: [ IconButton( icon: const Icon(Icons.close), onPressed: () => _hideMaterialBanner(), ), ], contentTextStyle: const TextStyle(color: Colors.white), backgroundColor: Colors.green, ), ); } void _hideMaterialBanner() { scaffoldMessengerKey.currentState!.hideCurrentMaterialBanner(); } ```

Logs

When the callback was called ``` I/Camera (26384): close E/libc (26384): Access denied finding property "persist.vendor.camera.privapp.list" I/Camera (26384): startPreview I/Camera (26384): CameraCaptureSession onConfigured I/Camera (26384): Updating builder settings D/Camera (26384): Updating builder with feature: ExposureLockFeature D/Camera (26384): Updating builder with feature: ExposurePointFeature D/Camera (26384): Updating builder with feature: ZoomLevelFeature D/Camera (26384): Updating builder with feature: AutoFocusFeature D/Camera (26384): Updating builder with feature: NoiseReductionFeature I/Camera (26384): updateNoiseReduction | currentSetting: fast D/Camera (26384): Updating builder with feature: FocusPointFeature D/Camera (26384): Updating builder with feature: ResolutionFeature D/Camera (26384): Updating builder with feature: SensorOrientationFeature D/Camera (26384): Updating builder with feature: FlashFeature D/Camera (26384): Updating builder with feature: ExposureOffsetFeature D/Camera (26384): Updating builder with feature: FpsRangeFeature I/Camera (26384): refreshPreviewCaptureSession I/Camera (26384): startPreviewWithImageStream I/Camera (26384): CameraCaptureSession onConfigured I/Camera (26384): Updating builder settings D/Camera (26384): Updating builder with feature: ExposureLockFeature D/Camera (26384): Updating builder with feature: ExposurePointFeature D/Camera (26384): Updating builder with feature: ZoomLevelFeature D/Camera (26384): Updating builder with feature: AutoFocusFeature D/Camera (26384): Updating builder with feature: NoiseReductionFeature I/Camera (26384): updateNoiseReduction | currentSetting: fast D/Camera (26384): Updating builder with feature: FocusPointFeature D/Camera (26384): Updating builder with feature: ResolutionFeature D/Camera (26384): Updating builder with feature: SensorOrientationFeature D/Camera (26384): Updating builder with feature: FlashFeature D/Camera (26384): Updating builder with feature: ExposureOffsetFeature D/Camera (26384): Updating builder with feature: FpsRangeFeature I/Camera (26384): refreshPreviewCaptureSession I/Camera (26384): refreshPreviewCaptureSession I/Camera (26384): CameraCaptureSession onClosed W/System (26384): A resource failed to call release. W/System (26384): A resource failed to call release. E/System (26384): Uncaught exception thrown by finalizer E/System (26384): java.util.concurrent.RejectedExecutionException: Task android.hardware.camera2.impl.-$$Lambda$CallbackProxies$SessionStateCallbackProxy$9H0ZdANdMrdpoq2bfIL2l3DVsKk@423824c rejected from java.util.concurrent.ThreadPoolExecutor@799d295[Shutting down, pool size = 1, active threads = 0, queued tasks = 0, completed tasks = 4] E/System (26384): at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2086) E/System (26384): at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:848) E/System (26384): at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1394) E/System (26384): at java.util.concurrent.Executors$DelegatedExecutorService.execute(Executors.java:630) E/System (26384): at android.hardware.camera2.impl.CallbackProxies$SessionStateCallbackProxy.onClosed(CallbackProxies.java:104) E/System (26384): at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:536) E/System (26384): at android.hardware.camera2.impl.CameraCaptureSessionImpl.finalize(CameraCaptureSessionImpl.java:827) E/System (26384): at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:289) E/System (26384): at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:276) E/System (26384): at java.lang.Daemons$Daemon.run(Daemons.java:137) E/System (26384): at java.lang.Thread.run(Thread.java:919) ```
When the callback was not called ``` I/Camera (26384): close E/libc (26384): Access denied finding property "persist.vendor.camera.privapp.list" I/Camera (26384): startPreview I/Camera (26384): CameraCaptureSession onConfigured I/Camera (26384): Updating builder settings D/Camera (26384): Updating builder with feature: ExposureLockFeature D/Camera (26384): Updating builder with feature: ExposurePointFeature D/Camera (26384): Updating builder with feature: ZoomLevelFeature D/Camera (26384): Updating builder with feature: AutoFocusFeature D/Camera (26384): Updating builder with feature: NoiseReductionFeature I/Camera (26384): updateNoiseReduction | currentSetting: fast D/Camera (26384): Updating builder with feature: FocusPointFeature D/Camera (26384): Updating builder with feature: ResolutionFeature D/Camera (26384): Updating builder with feature: SensorOrientationFeature D/Camera (26384): Updating builder with feature: FlashFeature D/Camera (26384): Updating builder with feature: ExposureOffsetFeature D/Camera (26384): Updating builder with feature: FpsRangeFeature I/Camera (26384): refreshPreviewCaptureSession I/Camera (26384): startPreviewWithImageStream I/Camera (26384): refreshPreviewCaptureSession I/Camera (26384): refreshPreviewCaptureSession: captureSession not yet initialized, skipping preview capture session refresh. I/Camera (26384): CameraCaptureSession onConfigured I/Camera (26384): Updating builder settings D/Camera (26384): Updating builder with feature: ExposureLockFeature D/Camera (26384): Updating builder with feature: ExposurePointFeature D/Camera (26384): Updating builder with feature: ZoomLevelFeature D/Camera (26384): Updating builder with feature: AutoFocusFeature D/Camera (26384): Updating builder with feature: NoiseReductionFeature I/Camera (26384): updateNoiseReduction | currentSetting: fast D/Camera (26384): Updating builder with feature: FocusPointFeature D/Camera (26384): Updating builder with feature: ResolutionFeature D/Camera (26384): Updating builder with feature: SensorOrientationFeature D/Camera (26384): Updating builder with feature: FlashFeature D/Camera (26384): Updating builder with feature: ExposureOffsetFeature D/Camera (26384): Updating builder with feature: FpsRangeFeature I/Camera (26384): refreshPreviewCaptureSession I/Camera (26384): CameraCaptureSession onClosed W/System (26384): A resource failed to call release. W/System (26384): A resource failed to call release. E/System (26384): Uncaught exception thrown by finalizer E/System (26384): java.util.concurrent.RejectedExecutionException: Task android.hardware.camera2.impl.-$$Lambda$CallbackProxies$SessionStateCallbackProxy$9H0ZdANdMrdpoq2bfIL2l3DVsKk@5fa07b2 rejected from java.util.concurrent.ThreadPoolExecutor@f79b303[Shutting down, pool size = 1, active threads = 0, queued tasks = 0, completed tasks = 3] E/System (26384): at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2086) E/System (26384): at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:848) E/System (26384): at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1394) E/System (26384): at java.util.concurrent.Executors$DelegatedExecutorService.execute(Executors.java:630) E/System (26384): at android.hardware.camera2.impl.CallbackProxies$SessionStateCallbackProxy.onClosed(CallbackProxies.java:104) E/System (26384): at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:536) E/System (26384): at android.hardware.camera2.impl.CameraCaptureSessionImpl.finalize(CameraCaptureSessionImpl.java:827) E/System (26384): at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:289) E/System (26384): at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:276) E/System (26384): at java.lang.Daemons$Daemon.run(Daemons.java:137) E/System (26384): at java.lang.Thread.run(Thread.java:919) ```

Environment

pubspec.yaml

dependencies:
  flutter:
    sdk: flutter

  flutter_zxing: ^1.1.1

I haven't checked 1.0.1 - 1.1.0, and I don't know either if it happens on iOS too.

khoren93 commented 1 year ago

Dear @kaboc,

I wanted to inform you that the issue you reported has been fixed in version v1.1.2. Please check to confirm that everything is working as expected.

Thank you for your attention.

kaboc commented 1 year ago

v1.1.2 is working fine. Thank you so much!