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
745 stars 444 forks source link

torchState Inverted after using toggleTorch #1041

Closed AndreLuizNogueira closed 2 weeks ago

AndreLuizNogueira commented 3 weeks ago

After Upgrading from 4.0.1 to 5.0.1 torchState is Inverted after using toggleTorch.

I am calling: await controller.toggleTorch(); final state = controller.value.torchState

torchState is on when my device flash is off and off when my device is on.

tested on android 13, POCO X5 PRO

flutter doctor -v [√] Flutter (Channel stable, 3.19.6, on Microsoft Windows [versÆo 10.0.22631.3447], locale pt-BR) • Flutter version 3.19.6 on channel stable at C:\Flutter\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 54e66469a9 (7 days ago), 2024-04-17 13:08:03 -0700 • Engine revision c4cd48e186 • Dart version 3.3.4 • DevTools version 2.31.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at C:\Users....\AppData\Local\Android\sdk • Platform android-34, build-tools 34.0.0 • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java • Java version OpenJDK Runtime Environment (build 17.0.9+0--11185874) • 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.9.6) • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community • Visual Studio Community 2022 version 17.9.34728.123 • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2023.2) • 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.9+0--11185874)

[√] VS Code (version 1.88.1) • VS Code at C:\Users....\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.86.0

[√] Connected device (4 available) • 22101320I (mobile) • e6f01007 • android-arm64 • Android 14 (API 34) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [versÆo 10.0.22631.3447] • Chrome (web) • chrome • web-javascript • Google Chrome 124.0.6367.61 • Edge (web) • edge • web-javascript • Microsoft Edge 123.0.2420.97

[√] Network resources • All expected network resources are available.

• No issues found!

navaronbracke commented 2 weeks ago

FYI: I am working on a fix for this bug at the moment.

navaronbracke commented 2 weeks ago

The new fix in version 5.0.2 defers to the native side for determining the new state of the torch, with updates coming through the torch state stream. @AndreLuizNogueira Can you verify if this fix resolves your issue?

AndreLuizNogueira commented 2 weeks ago

The new fix in version 5.0.2 defers to the native side for determining the new state of the torch, with updates coming through the torch state stream. @AndreLuizNogueira Can you verify if this fix resolves your issue?

It changed, but not Immediately after calling await controller.value.torchState, and I had to add a setstate

navaronbracke commented 2 weeks ago

The controller's value does not need an await, since the controller is a ValueNotifier.

Is using the controller in a ValueListenableBuilder sufficient? If not, we can look into updating the state right after calling toggleTorch(). Should be easy to do anyway, now that we also have the immediate state update when the controller is started, I think we can reduce the dependency on the torchStateStream.

AndreLuizNogueira commented 2 weeks ago

The controller's value does not need an await, since the controller is a ValueNotifier.

Is using the controller in a ValueListenableBuilder sufficient? If not, we can look into updating the state right after calling toggleTorch(). Should be easy to do anyway, now that we also have the immediate state update when the controller is started, I think we can reduce the dependency on the torchStateStream.

Sorry. I meant await controller.toggleTorch(). It doesn't update immediately after this.

navaronbracke commented 2 weeks ago

The controller's value does not need an await, since the controller is a ValueNotifier. Is using the controller in a ValueListenableBuilder sufficient? If not, we can look into updating the state right after calling toggleTorch(). Should be easy to do anyway, now that we also have the immediate state update when the controller is started, I think we can reduce the dependency on the torchStateStream.

Sorry. I meant await controller.toggleTorch(). It doesn't update immediately after this.

Yes, currently torch updates are received only through the torch state stream. PR #1048 added the initial torch state to the start call as well, but we need to do the same for toggle torch (getting the new torch state as a result of toggle torch)