Skip to content

[camera] plugin Cannot change flashMode to FlashMode.off in front camera #82627

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

Closed
II11II opened this issue May 15, 2021 · 5 comments
Closed
Labels

Comments

@II11II
Copy link

II11II commented May 15, 2021

When setFlashMode to FlashMode.off it throws errors
Test device: Samsung s9 android 10

I/flutter (19389): [setFlashModeFailed, Device does not have flash capabilities]
I/flutter (19389): [CameraException(setFlashModeFailed, Device does not have flash capabilities), #0      CameraController.setFlashMode (package:camera/src/camera_controller.dart:577:7)
I/flutter (19389): <asynchronous suspension>
I/flutter (19389): #1      _AppCameraState.setFlashMode (package:yool/app/presentation/page/camera/app_camera.dart:482:7)
I/flutter (19389): <asynchronous suspension>
I/flutter (19389): #2      _AppCameraState.cameraButtons.<anonymous closure>.<anonymous closure> (package:yool/app/presentation/page/camera/app_camera.dart:319:20)
I/flutter (19389): <asynchronous suspension>
I/flutter (19389): ]

camera: ^0.8.1

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.0.5, on macOS 11.3 20E232 darwin-arm, locale
    ru-UZ)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2020.3.2)
[✓] VS Code (version 1.56.0)
[✓] Connected device (3 available)
    ! Error: iPhone is not connected. Xcode will continue when iPhone is
      connected. (code -13)

• No issues found!
@II11II
Copy link
Author

II11II commented May 15, 2021

Extra output

I/ViewRootImpl@8f7ded2[MainActivity](19389): ViewPostIme pointer 0
I/ViewRootImpl@8f7ded2[MainActivity](19389): ViewPostIme pointer 1
I/ViewRootImpl@8f7ded2[MainActivity](19389): ViewPostIme pointer 0
I/ViewRootImpl@8f7ded2[MainActivity](19389): ViewPostIme pointer 1
I/ViewRootImpl@8f7ded2[MainActivity](19389): ViewPostIme pointer 0
I/ViewRootImpl@8f7ded2[MainActivity](19389): ViewPostIme pointer 1
I/CameraManagerGlobal(19389): Camera 2 facing CAMERA_FACING_FRONT state now CAMERA_STATE_IDLE for client uz.yim.yool API Level 2
I/CameraManagerGlobal(19389): Camera 2 facing CAMERA_FACING_FRONT state now CAMERA_STATE_CLOSED for client uz.yim.yool API Level 2
I/Camera  (19389): [FPS Range Available] is:[15, 15]
I/Camera  (19389): [FPS Range Available] is:[15, 20]
I/Camera  (19389): [FPS Range Available] is:[20, 20]
I/Camera  (19389): [FPS Range Available] is:[10, 24]
I/Camera  (19389): [FPS Range Available] is:[24, 24]
I/Camera  (19389): [FPS Range Available] is:[7, 30]
I/Camera  (19389): [FPS Range Available] is:[8, 30]
I/Camera  (19389): [FPS Range Available] is:[10, 30]
I/Camera  (19389): [FPS Range Available] is:[15, 30]
I/Camera  (19389): [FPS Range Available] is:[30, 30]
I/Camera  (19389): [FPS Range] is:[7, 30]
D/SensorManager(19389): registerListener :: 1, LSM6DSL Acceleration Sensor, 200000, 0,  
E/MethodChannel#plugins.flutter.io/camera(19389): Failed to handle method call
E/MethodChannel#plugins.flutter.io/camera(19389): java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.hardware.camera2.CameraDevice.getId()' on a null object reference
E/MethodChannel#plugins.flutter.io/camera(19389): 	at io.flutter.plugins.camera.Camera.setFlashMode(Camera.java:717)
E/MethodChannel#plugins.flutter.io/camera(19389): 	at io.flutter.plugins.camera.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.java:142)
E/MethodChannel#plugins.flutter.io/camera(19389): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/MethodChannel#plugins.flutter.io/camera(19389): 	at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#plugins.flutter.io/camera(19389): 	at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818)
E/MethodChannel#plugins.flutter.io/camera(19389): 	at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/camera(19389): 	at android.os.MessageQueue.next(MessageQueue.java:336)
E/MethodChannel#plugins.flutter.io/camera(19389): 	at android.os.Looper.loop(Looper.java:197)
E/MethodChannel#plugins.flutter.io/camera(19389): 	at android.app.ActivityThread.main(ActivityThread.java:8167)
E/MethodChannel#plugins.flutter.io/camera(19389): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/camera(19389): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
E/MethodChannel#plugins.flutter.io/camera(19389): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
I/CameraManagerGlobal(19389): Camera 2 facing CAMERA_FACING_FRONT state now CAMERA_STATE_OPEN for client uz.yim.yool API Level 2
I/flutter (19389): [CameraException(error, Attempt to invoke virtual method 'java.lang.String android.hardware.camera2.CameraDevice.getId()' on a null object reference), #0      CameraController.setFlashMode (package:camera/src/camera_controller.dart:577:7)
I/flutter (19389): <asynchronous suspension>
I/flutter (19389): #1      _AppCameraState.initCamera (package:yool/app/presentation/page/camera/app_camera.dart:100:4)
I/flutter (19389): <asynchronous suspension>
I/flutter (19389): #2      _AppCameraState._getAvailableCameras (package:yool/app/presentation/page/camera/app_camera.dart:81:7)
I/flutter (19389): <asynchronous suspension>
I/flutter (19389): ]
I/CameraManagerGlobal(19389): Camera 2 facing CAMERA_FACING_FRONT state now CAMERA_STATE_ACTIVE for client uz.yim.yool API Level 2

@II11II
Copy link
Author

II11II commented May 15, 2021

This code makes to throw error:

 @override
  void initState() {
    super.initState();

    WidgetsBinding.instance?.addObserver(this);
    _getAvailableCameras();
  }

  Future<void> _getAvailableCameras() async {
    cameras = await availableCameras();

    if (cameras.isNotEmpty) {
      await initCamera(cameras.last);
    }
  }

  Future<void> initCamera(CameraDescription cameraDescription) async {
    if (controller != null) controller!.dispose();
    controller = CameraController(
        // Get a specific camera from the list of available cameras.
        cameraDescription,
        // Define the resolution to use.
        ResolutionPreset.max,
        enableAudio: true,
        imageFormatGroup: ImageFormatGroup.jpeg);


    controller!.initialize().then((value) => setState(() {

          _flashNotifier.value = controller!.value.flashMode;
        }));
   await controller!.setFlashMode(FlashMode.off);
  }

@darshankawar darshankawar added the in triage Presently being triaged by the triage team label May 17, 2021
@darshankawar
Copy link
Member

@II11II
It'd be great if you could provide a complete reproducible code sample that we can directly copy paste and run to verify the issue.

Using your code, I am getting compile error on flashNotifier:

Screenshot 2021-05-17 at 4 08 47 PM

Also, can you test your code against this PR and see if it resolves your issue ?
flutter/plugins#3651

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 17, 2021
@II11II
Copy link
Author

II11II commented May 18, 2021

@II11II
It'd be great if you could provide a complete reproducible code sample that we can directly copy paste and run to verify the issue.

Using your code, I am getting compile error on flashNotifier:

Screenshot 2021-05-17 at 4 08 47 PM

Also, can you test your code against this PR and see if it resolves your issue ?
flutter/plugins#3651

Hi @darshankawar 🖐
Thank you

flutter/plugins#3651 (comment)

This pr helped to solve this issue.

Please, Flutter team allow this pr to be merged

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 18, 2021
@II11II II11II closed this as completed May 18, 2021
@darshankawar darshankawar added waiting for PR to land (fixed) A fix is in flight and removed in triage Presently being triaged by the triage team labels May 18, 2021
@github-actions
Copy link

github-actions bot commented Aug 1, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants