initializeCameraById method

Future<void> initializeCameraById({
  1. required int camera_id,
  2. required void setState(
    1. void callback()
    ),
  3. required bool mounted(),
})

Implementation

Future<void> initializeCameraById({
  required int camera_id,
  required void Function(void Function() callback) setState,
  required bool Function() mounted,
}) async {
  if (!is_camera_init) {
    return;
  }
  if (isMobile) {
    for (var i = 0; i < camera_mobile_datas.length; i++) {
      camera_package.CameraDescription camera_mobile_data =
          camera_mobile_datas[i];
      if (i == (camera_id - 1)) {
        camera_mobile_controller = camera_package.CameraController(
          camera_mobile_data,
          camera_package.ResolutionPreset.max,
        );
        is_select_camera = true;
        await activateCamera(setState: setState, mounted: mounted);
        return;
      }
    }
  }
  if (isDesktop) {
    if (Platform.isWindows) {
      for (var i = 0; i < camera_mobile_datas.length; i++) {
        camera_package.CameraDescription camera_mobile_data =
            camera_mobile_datas[i];
        if (i == (camera_id - 1)) {
          camera_id = await camera_windows.createCamera(
            camera_mobile_data,
            camera_package.ResolutionPreset.max,
          );
          is_select_camera = true;
          await activateCamera(setState: setState, mounted: mounted);
          return;
        }
      }
    }
  }
  return;
}