Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Better support for Hot Reload #773

Open
laterdayi opened this issue Oct 10, 2023 · 12 comments
Open

Better support for Hot Reload #773

laterdayi opened this issue Oct 10, 2023 · 12 comments
Assignees
Labels
bug Something isn't working

Comments

@laterdayi
Copy link

Using Hot Reload on either iOS or Android on view with camera causes MobileScanner: Called start() while already started! error.

Repro steps:

build example app to device
open any camera screen
do Hot Reload

This problem still exists in the latest version

@navaronbracke navaronbracke self-assigned this Oct 12, 2023
@navaronbracke
Copy link
Collaborator

This does not reproduce on Android/iOS with hot reload/hot restart on version 3.5.1 for the example app.

@laterdayi
Copy link
Author

I use the latest versions of flutter and mobile_scanner, and this issue still occurs when hot reloading, which I will try to repeat later

@navaronbracke
Copy link
Collaborator

@laterdayi Does this reproduce on version 5.0.0-beta.1 ? We fixed the lifecycle management issues in that release, so I think that solves this bug.

@y-az
Copy link

y-az commented Mar 8, 2024

Hi @navaronbracke I'm on version 5.0.0-beta.1 and I'm running into this error

@navaronbracke
Copy link
Collaborator

Okay, then I think I know what is happening. The package will have to listen to hot reload events to prevent this issue from happening.

We might be able to leverage https://api.flutter.dev/flutter/widgets/State/reassemble.html

@navaronbracke navaronbracke added the bug Something isn't working label Mar 8, 2024
@navaronbracke navaronbracke changed the title Hot Reload Error Better support for Hot Reload Mar 8, 2024
@EArminjon
Copy link
Contributor

(maybe this topic can help once fixed : flutter/flutter#10437)

@lukepighetti
Copy link

i get this issue with hot restart, not hot reload

@navaronbracke
Copy link
Collaborator

@lukepighetti I published a patch on the master branch #1086 that hopefully fixes this issue. I plan on publishing this fix today. If you feel like verifying it on your end (using a git override), feel free to do so.

@antoinepemeja
Copy link

antoinepemeja commented Oct 24, 2024

I confirm that the issue occurs after a hot restart (not a hot reload). If I perform a hot restart with the camera already open, the screen turns black when I open camera again, but the scanning functionality continues to work. I have to restart build to fix the problem.

I’m using mobile_scanner: ^6.0.2 and developing on a physical iPhone 13 mini (iOS 17.6.1).

I’m also using the controller approach as indicated in this example: Barcode Scanner Controller Example.

[✓] Flutter (Channel stable, 3.24.3, on macOS 14.5 23F79 darwin-arm64, locale
    fr-CA)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.1)
[✓] VS Code (version 1.94.2)
[✓] Connected device (6 available)
[✓] Network resources

EDIT add logs:

MOBILE_SCANNER_ALREADY_STARTED_ERROR

PlatformException (PlatformException(MOBILE_SCANNER_ALREADY_STARTED_ERROR, The scanner was already started., null, null))

MethodChannel.invokeMapMethod (/Users/---/Documents/flutter/packages/flutter/lib/src/services/platform_channel.dart:534)
<asynchronous gap> (Unknown Source:0)
MethodChannelMobileScanner.start (/Users/---/.pub-cache/hosted/pub.dev/mobile_scanner-6.0.2/lib/src/method_channel/mobile_scanner_method_channel.dart:233)
<asynchronous gap> (Unknown Source:0)
MobileScannerController.start (/Users/---/.pub-cache/hosted/pub.dev/mobile_scanner-6.0.2/lib/src/mobile_scanner_controller.dart:292)
<asynchronous gap> (Unknown Source:0)

EDIT 2 : issue still there with v7.0.0-beta.3

@navaronbracke
Copy link
Collaborator

the screen turns black when I open camera again, but the scanning functionality continues to work

Do you have any logs of when that occurred? Do you hit the controllerAlreadyInitialized error code?

@maxfrees
Copy link

same, this problem is still there

@navaronbracke
Copy link
Collaborator

Interesting. So the error comes back as a PlatformException, but we only catch MobileScannerException at https://github.com/juliansteenbakker/mobile_scanner/blob/master/lib/src/mobile_scanner_controller.dart#L308-L314

with the same error code. Since the catch clause only runs on the former, but not the latter, it turns into an unhandled error.

But then I wonder why the catch on https://github.com/juliansteenbakker/mobile_scanner/blob/master/lib/src/method_channel/mobile_scanner_method_channel.dart#L232-L237 did not catch this. That one does handle PlatformExceptions

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants