initialize method

Future<void> initialize()

Initializes the camera on the device.

Throws a CameraException if the initialization fails.

Implementation

Future<void> initialize() async {
  if (_isDisposed) {
    return Future<void>.value();
  }
  try {
    _creatingCompleter = Completer<void>();
    final Map<String, dynamic> reply =
    (await _channel.invokeMapMethod<String, dynamic>(
      'initialize',
      <String, dynamic>{
        'cameraName': description.name,
        'resolutionPreset': serializeResolutionPreset(resolutionPreset),
        'enableAudio': enableAudio,
        'autoFocusEnabled': autoFocusEnabled,
        'enableAutoExposure': enableAutoExposure,
        'flashMode': flashMode.index,
      },
    )) as Map<String, dynamic>;
    _textureId = reply['textureId'];
    value = value.copyWith(
      isInitialized: true,
      previewSize: Size(
        reply['previewWidth'].toDouble(),
        reply['previewHeight'].toDouble(),
      ),
    );
  } on PlatformException catch (e) {
    throw CameraException(e.code, e.message);
  }

  _eventSubscription =
      EventChannel('flutter.io/cameraPlugin/cameraEvents$_textureId')
          .receiveBroadcastStream()
          .listen(_listener);
  _creatingCompleter!.complete();
  return _creatingCompleter!.future;
}