CamerAwesome icon indicating copy to clipboard operation
CamerAwesome copied to clipboard

Initial camera flash mode not set on widget init

Open markfili opened this issue 3 years ago • 1 comments

Trigger CA plugin's setFlashMode after Flash mode switcher init

It is observed that setting the initial ValueNotifier<CameraFlashes> value does not call the plugin to set a Flash mode. Init method only adds a listener for value changes:

/// inits the Flash mode switcher using [ValueNotifier]
/// Each time user call to switch flashMode we send a call to iOS or Android Plugins
_initFlashModeSwitcher() async {
  if (widget.switchFlashMode != null) {
    widget.switchFlashMode.addListener(() async {
      if (widget.switchFlashMode.value != null && started) {
        await CamerawesomePlugin.setFlashMode(widget.switchFlashMode.value);
      }
    });
  }
} 

A quick suggestion would be to call the await CamerawesomePlugin.setFlashMode(widget.switchFlashMode.value); method after attaching the listener or somehow trigger the ValueNotifier so that the mode is set.

/// inits the Flash mode switcher using [ValueNotifier]
/// Each time user call to switch flashMode we send a call to iOS or Android Plugins
_initFlashModeSwitcher() async {
  if (widget.switchFlashMode != null) {
    widget.switchFlashMode.addListener(() async {
      if (widget.switchFlashMode.value != null && started) {
        await CamerawesomePlugin.setFlashMode(widget.switchFlashMode.value);
      }
    });
    ----> await CamerawesomePlugin.setFlashMode(widget.switchFlashMode.value); <----
  }
} 

markfili avatar Mar 08 '21 17:03 markfili

Good one yes. I put this as a bug

g-apparence avatar Mar 08 '21 20:03 g-apparence