@@ -318,18 +318,18 @@ class CameraPickerState extends State<CameraPicker>
318318 Future <T ?> wrapControllerMethod <T >(
319319 String key,
320320 Future <T > Function () method, {
321- CameraDescription ? description ,
321+ CameraDescription ? camera ,
322322 VoidCallback ? onError,
323323 T ? fallback,
324324 }) async {
325- description ?? = currentCamera;
326- if (invalidControllerMethods[description ]! .contains (key)) {
325+ camera ?? = currentCamera;
326+ if (invalidControllerMethods[camera ]! .contains (key)) {
327327 return fallback;
328328 }
329329 try {
330330 return await method ();
331331 } catch (e) {
332- invalidControllerMethods[description ]! .add (key);
332+ invalidControllerMethods[camera ]! .add (key);
333333 onError? .call ();
334334 rethrow ;
335335 }
@@ -407,10 +407,10 @@ class CameraPickerState extends State<CameraPicker>
407407 index = currentCameraIndex;
408408 }
409409 // Initialize the controller with the given resolution preset.
410- final description = cameraDescription ?? cameras[index];
411- invalidControllerMethods[description ] ?? = < String > {};
410+ final camera = cameraDescription ?? cameras[index];
411+ invalidControllerMethods[camera ] ?? = < String > {};
412412 final CameraController newController = CameraController (
413- description ,
413+ camera ,
414414 pickerConfig.resolutionPreset,
415415 enableAudio: enableAudio,
416416 imageFormatGroup: pickerConfig.imageFormatGroup,
@@ -440,37 +440,37 @@ class CameraPickerState extends State<CameraPicker>
440440 wrapControllerMethod (
441441 'getExposureOffsetStepSize' ,
442442 () => newController.getExposureOffsetStepSize (),
443- description : description ,
443+ camera : camera ,
444444 fallback: exposureStep,
445445 ).then ((value) => exposureStep = value! ),
446446 wrapControllerMethod (
447447 'getMaxExposureOffset' ,
448448 () => newController.getMaxExposureOffset (),
449- description : description ,
449+ camera : camera ,
450450 fallback: maxAvailableExposureOffset,
451451 ).then ((value) => maxAvailableExposureOffset = value! ),
452452 wrapControllerMethod (
453453 'getMinExposureOffset' ,
454454 () => newController.getMinExposureOffset (),
455- description : description ,
455+ camera : camera ,
456456 fallback: minAvailableExposureOffset,
457457 ).then ((value) => minAvailableExposureOffset = value! ),
458458 wrapControllerMethod (
459459 'getMaxZoomLevel' ,
460460 () => newController.getMaxZoomLevel (),
461- description : description ,
461+ camera : camera ,
462462 fallback: maxAvailableZoom,
463463 ).then ((value) => maxAvailableZoom = value! ),
464464 wrapControllerMethod (
465465 'getMinZoomLevel' ,
466466 () => newController.getMinZoomLevel (),
467- description : description ,
467+ camera : camera ,
468468 fallback: minAvailableZoom,
469469 ).then ((value) => minAvailableZoom = value! ),
470470 wrapControllerMethod (
471471 'getMinZoomLevel' ,
472472 () => newController.getMinZoomLevel (),
473- description : description ,
473+ camera : camera ,
474474 fallback: minAvailableZoom,
475475 ).then ((value) => minAvailableZoom = value! ),
476476 if (pickerConfig.lockCaptureOrientation != null )
@@ -479,23 +479,24 @@ class CameraPickerState extends State<CameraPicker>
479479 () => newController.lockCaptureOrientation (
480480 pickerConfig.lockCaptureOrientation,
481481 ),
482- description : description ,
482+ camera : camera ,
483483 ),
484484 // Do not set flash modes for the front camera.
485- if (description.lensDirection != CameraLensDirection .front &&
486- pickerConfig.preferredFlashMode != FlashMode .auto)
487- wrapControllerMethod <void >(
488- 'setFlashMode' ,
489- () => newController.setFlashMode (
490- pickerConfig.preferredFlashMode,
491- ),
492- description: description,
493- onError: () {
494- validFlashModes[description]? .remove (
495- pickerConfig.preferredFlashMode,
485+ if (camera.lensDirection != CameraLensDirection .front)
486+ Future (() async {
487+ final flashMode = pickerConfig.preferredFlashMode;
488+ if (flashMode != FlashMode .auto &&
489+ validFlashModes[camera]? .contains (flashMode) != false ) {
490+ return wrapControllerMethod <void >(
491+ 'setFlashMode' ,
492+ () => newController.setFlashMode (flashMode),
493+ camera: camera,
494+ onError: () {
495+ validFlashModes[camera]? .remove (flashMode);
496+ },
496497 );
497- },
498- ),
498+ }
499+ } ),
499500 ],
500501 eagerError: false ,
501502 );
0 commit comments