tryReadBarCode method

Future<String> tryReadBarCode(
  1. ReadBarcodeProps readBarcodeProps,
  2. BarcodeReaderWebassemblyEvent method
)

Implementation

Future<String> tryReadBarCode(
  ReadBarcodeProps readBarcodeProps,
  BarcodeReaderWebassemblyEvent method,
) async {
  try {
    final call = MethodCall(
      DartWebPluginBaseChannelMessage.sendMethodMessageToClient.name,
      buildArguments(readBarcodeProps, method),
    );

    final dartWebPlugin =
        DartWebPluginBase<String, BarcodeReaderWebassemblyJsProps, String>(
            null);
    final result = await dartWebPlugin.invokeMethodJs(call);
    return result.arguments;
  } catch (e) {
    final isPasswordException = e.toString().contains('PasswordException');
    if (isPasswordException) {
      final onRequiredPassword = readBarcodeProps.onRequiredPassword;
      if (onRequiredPassword != null) {
        readBarcodeProps.password = await onRequiredPassword();
        return tryReadBarCode(readBarcodeProps, method);
      }
    }
  }
  return '';
}