startCapture method

Future<int?> startCapture({
  1. BackgroundCaptureConfig config = const BackgroundCaptureConfig(),
})

Start capturing the background behind this palette window.

Returns the texture ID that can be used with Texture widget. Returns null if capture fails to start.

Implementation

Future<int?> startCapture({
  BackgroundCaptureConfig config = const BackgroundCaptureConfig(),
}) async {
  try {
    final result = await _channel.invokeMethod<int>(
      'backgroundCapture.start',
      config.toMap(),
    );
    if (result != null) {
      _eventController.add(BackgroundCaptureEvent(
        paletteId: '',
        type: 'started',
        data: {'textureId': result},
      ));
    }
    return result;
  } on PlatformException catch (e) {
    _eventController.add(BackgroundCaptureEvent(
      paletteId: '',
      type: 'error',
      data: {'error': e.message ?? 'Unknown error'},
    ));
    return null;
  }
}