handleCameraMethodCall method

  1. @visibleForTesting
Future handleCameraMethodCall(
  1. MethodCall call,
  2. int cameraId
)

Converts messages received from the native platform into camera events.

This is only exposed for test purposes. It shouldn't be used by clients of the plugin as it may break or change at any time.

Implementation

@visibleForTesting
Future<dynamic> handleCameraMethodCall(MethodCall call, int cameraId) async {
  switch (call.method) {
    case 'initialized':
      final Map<String, Object?> arguments = _getArgumentDictionary(call);
      cameraEventStreamController.add(CameraInitializedEvent(
        cameraId,
        arguments['previewWidth']! as double,
        arguments['previewHeight']! as double,
        deserializeExposureMode(arguments['exposureMode']! as String),
        arguments['exposurePointSupported']! as bool,
        deserializeFocusMode(arguments['focusMode']! as String),
        arguments['focusPointSupported']! as bool,
      ));
    case 'resolution_changed':
      final Map<String, Object?> arguments = _getArgumentDictionary(call);
      cameraEventStreamController.add(CameraResolutionChangedEvent(
        cameraId,
        arguments['captureWidth']! as double,
        arguments['captureHeight']! as double,
      ));
    case 'camera_closing':
      cameraEventStreamController.add(CameraClosingEvent(
        cameraId,
      ));
    case 'video_recorded':
      final Map<String, Object?> arguments = _getArgumentDictionary(call);
      cameraEventStreamController.add(VideoRecordedEvent(
        cameraId,
        XFile(arguments['path']! as String),
        arguments['maxVideoDuration'] != null
            ? Duration(milliseconds: arguments['maxVideoDuration']! as int)
            : null,
      ));
    case 'error':
      final Map<String, Object?> arguments = _getArgumentDictionary(call);
      cameraEventStreamController.add(CameraErrorEvent(
        cameraId,
        arguments['description']! as String,
      ));
    default:
      throw MissingPluginException();
  }
}