chooseCaptureMode method

Future<Uint8List?> chooseCaptureMode({
  1. required Image image,
  2. required String id,
})

Selects the appropriate capture mode based on the platform and configuration.

This function determines the capture mode based on the platform and configuration settings specified in _configs. If the configuration allows, the image generation may be offloaded to a separate thread or web worker for better performance. If an error occurs, it falls back to the main thread.

Implementation

Future<Uint8List?> chooseCaptureMode({
  required ui.Image image,
  required String id,
}) async {
  if (_configs.imageGenerationConfigs.generateInsideSeparateThread) {
    try {
      if (!kIsWeb) {
        // Run in dart native the thread isolated.
        return await _captureWithNativeIsolated(
          image: image,
          id: id,
        );
      } else {
        // Run in web worker
        return await _captureWithWebWorker(
          image: image,
          id: id,
        );
      }
    } catch (e) {
      // Fallback to the main thread.
      debugPrint('Fallback to main thread: $e');
      return await _captureWithMainThread(image: image);
    }
  } else {
    return await _captureWithMainThread(image: image);
  }
}