Apparence-io / CamerAwesome

📸 Embedding a camera experience within your own app shouldn't be that hard. A flutter plugin to integrate awesome Android / iOS camera experience.
https://ApparenceKit.dev
MIT License
976 stars 256 forks source link

Initial camera flash mode not set on widget init #88

Closed markfili closed 2 years ago

markfili commented 3 years ago

Trigger CA plugin's setFlashMode after Flash mode switcher init

It is observed that setting the initial ValueNotifier 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); <----
  }
} 
g-apparence commented 3 years ago

Good one yes. I put this as a bug