scan static method

Future<List<String>?> scan({
  1. DocScanFormat format = DocScanFormat.jpeg,
})

Scans a document and returns the file path(s) of the scanned document(s).

Throws a DocumentScannerException if the scan fails.

Implementation

static Future<List<String>?> scan({
  DocScanFormat format = DocScanFormat.jpeg,
}) async {
  try {
    final result = await _channel.invokeMethod('scanDocument', {
      'format': format == DocScanFormat.pdf ? 'pdf' : 'jpeg',
    });

    if (result == null || result is! List) {
      throw DocumentScannerException(
        'Invalid response from native code, expected a List, got $result',
      );
    }

    return result.cast<String>();
  } on PlatformException catch (e) {
    throw DocumentScannerException(e.message ?? 'Unknown error');
  }
}