@@ -555,9 +555,9 @@ class AVFoundationCamera extends CameraPlatform {
555555 Future <dynamic > _handleDeviceMethodCall (MethodCall call) async {
556556 switch (call.method) {
557557 case 'orientation_changed' :
558+ final Map <String , Object ?> arguments = _getArgumentDictionary (call);
558559 _deviceEventStreamController.add (DeviceOrientationChangedEvent (
559- deserializeDeviceOrientation (
560- call.arguments['orientation' ]! as String )));
560+ deserializeDeviceOrientation (arguments['orientation' ]! as String )));
561561 break ;
562562 default :
563563 throw MissingPluginException ();
@@ -572,21 +572,23 @@ class AVFoundationCamera extends CameraPlatform {
572572 Future <dynamic > handleCameraMethodCall (MethodCall call, int cameraId) async {
573573 switch (call.method) {
574574 case 'initialized' :
575+ final Map <String , Object ?> arguments = _getArgumentDictionary (call);
575576 cameraEventStreamController.add (CameraInitializedEvent (
576577 cameraId,
577- call. arguments['previewWidth' ]! as double ,
578- call. arguments['previewHeight' ]! as double ,
579- deserializeExposureMode (call. arguments['exposureMode' ]! as String ),
580- call. arguments['exposurePointSupported' ]! as bool ,
581- deserializeFocusMode (call. arguments['focusMode' ]! as String ),
582- call. arguments['focusPointSupported' ]! as bool ,
578+ arguments['previewWidth' ]! as double ,
579+ arguments['previewHeight' ]! as double ,
580+ deserializeExposureMode (arguments['exposureMode' ]! as String ),
581+ arguments['exposurePointSupported' ]! as bool ,
582+ deserializeFocusMode (arguments['focusMode' ]! as String ),
583+ arguments['focusPointSupported' ]! as bool ,
583584 ));
584585 break ;
585586 case 'resolution_changed' :
587+ final Map <String , Object ?> arguments = _getArgumentDictionary (call);
586588 cameraEventStreamController.add (CameraResolutionChangedEvent (
587589 cameraId,
588- call. arguments['captureWidth' ]! as double ,
589- call. arguments['captureHeight' ]! as double ,
590+ arguments['captureWidth' ]! as double ,
591+ arguments['captureHeight' ]! as double ,
590592 ));
591593 break ;
592594 case 'camera_closing' :
@@ -595,23 +597,32 @@ class AVFoundationCamera extends CameraPlatform {
595597 ));
596598 break ;
597599 case 'video_recorded' :
600+ final Map <String , Object ?> arguments = _getArgumentDictionary (call);
598601 cameraEventStreamController.add (VideoRecordedEvent (
599602 cameraId,
600- XFile (call.arguments['path' ]! as String ),
601- call.arguments['maxVideoDuration' ] != null
602- ? Duration (
603- milliseconds: call.arguments['maxVideoDuration' ]! as int )
603+ XFile (arguments['path' ]! as String ),
604+ arguments['maxVideoDuration' ] != null
605+ ? Duration (milliseconds: arguments['maxVideoDuration' ]! as int )
604606 : null ,
605607 ));
606608 break ;
607609 case 'error' :
610+ final Map <String , Object ?> arguments = _getArgumentDictionary (call);
608611 cameraEventStreamController.add (CameraErrorEvent (
609612 cameraId,
610- call. arguments['description' ]! as String ,
613+ arguments['description' ]! as String ,
611614 ));
612615 break ;
613616 default :
614617 throw MissingPluginException ();
615618 }
616619 }
620+
621+ /// Returns the arguments of [call] as typed string-keyed Map.
622+ ///
623+ /// This does not do any type validation, so is only safe to call if the
624+ /// arguments are known to be a map.
625+ Map <String , Object ?> _getArgumentDictionary (MethodCall call) {
626+ return (call.arguments as Map <Object ?, Object ?>).cast <String , Object ?>();
627+ }
617628}
0 commit comments