@@ -318,18 +318,18 @@ class CameraPickerState extends State<CameraPicker>
318
318
Future <T ?> wrapControllerMethod <T >(
319
319
String key,
320
320
Future <T > Function () method, {
321
- CameraDescription ? description ,
321
+ CameraDescription ? camera ,
322
322
VoidCallback ? onError,
323
323
T ? fallback,
324
324
}) async {
325
- description ?? = currentCamera;
326
- if (invalidControllerMethods[description ]! .contains (key)) {
325
+ camera ?? = currentCamera;
326
+ if (invalidControllerMethods[camera ]! .contains (key)) {
327
327
return fallback;
328
328
}
329
329
try {
330
330
return await method ();
331
331
} catch (e) {
332
- invalidControllerMethods[description ]! .add (key);
332
+ invalidControllerMethods[camera ]! .add (key);
333
333
onError? .call ();
334
334
rethrow ;
335
335
}
@@ -407,10 +407,10 @@ class CameraPickerState extends State<CameraPicker>
407
407
index = currentCameraIndex;
408
408
}
409
409
// 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 > {};
412
412
final CameraController newController = CameraController (
413
- description ,
413
+ camera ,
414
414
pickerConfig.resolutionPreset,
415
415
enableAudio: enableAudio,
416
416
imageFormatGroup: pickerConfig.imageFormatGroup,
@@ -440,37 +440,37 @@ class CameraPickerState extends State<CameraPicker>
440
440
wrapControllerMethod (
441
441
'getExposureOffsetStepSize' ,
442
442
() => newController.getExposureOffsetStepSize (),
443
- description : description ,
443
+ camera : camera ,
444
444
fallback: exposureStep,
445
445
).then ((value) => exposureStep = value! ),
446
446
wrapControllerMethod (
447
447
'getMaxExposureOffset' ,
448
448
() => newController.getMaxExposureOffset (),
449
- description : description ,
449
+ camera : camera ,
450
450
fallback: maxAvailableExposureOffset,
451
451
).then ((value) => maxAvailableExposureOffset = value! ),
452
452
wrapControllerMethod (
453
453
'getMinExposureOffset' ,
454
454
() => newController.getMinExposureOffset (),
455
- description : description ,
455
+ camera : camera ,
456
456
fallback: minAvailableExposureOffset,
457
457
).then ((value) => minAvailableExposureOffset = value! ),
458
458
wrapControllerMethod (
459
459
'getMaxZoomLevel' ,
460
460
() => newController.getMaxZoomLevel (),
461
- description : description ,
461
+ camera : camera ,
462
462
fallback: maxAvailableZoom,
463
463
).then ((value) => maxAvailableZoom = value! ),
464
464
wrapControllerMethod (
465
465
'getMinZoomLevel' ,
466
466
() => newController.getMinZoomLevel (),
467
- description : description ,
467
+ camera : camera ,
468
468
fallback: minAvailableZoom,
469
469
).then ((value) => minAvailableZoom = value! ),
470
470
wrapControllerMethod (
471
471
'getMinZoomLevel' ,
472
472
() => newController.getMinZoomLevel (),
473
- description : description ,
473
+ camera : camera ,
474
474
fallback: minAvailableZoom,
475
475
).then ((value) => minAvailableZoom = value! ),
476
476
if (pickerConfig.lockCaptureOrientation != null )
@@ -479,23 +479,24 @@ class CameraPickerState extends State<CameraPicker>
479
479
() => newController.lockCaptureOrientation (
480
480
pickerConfig.lockCaptureOrientation,
481
481
),
482
- description : description ,
482
+ camera : camera ,
483
483
),
484
484
// 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
+ },
496
497
);
497
- },
498
- ),
498
+ }
499
+ } ),
499
500
],
500
501
eagerError: false ,
501
502
);
0 commit comments