engageDevice method

Future<(DeviceEngagement?, DocReaderException?)> engageDevice(
  1. MDLDeviceEngagement type, {
  2. bool withoutUI = false,
  3. String? data,
})

Used to engage device.

withoutUI - If true, then Regula's UI will not be shown and user is supposed to implement the UI himself.

data - Required if type = MDLDeviceEngagement.QR and withoutUI = true.

Implementation

Future<(DeviceEngagement? engagement, DocReaderException? error)>
    engageDevice(
  MDLDeviceEngagement type, {
  bool withoutUI = false,
  String? data,
}) async {
  String response = "";
  if (withoutUI == false) {
    response = await _bridge.invokeMethod("startEngageDevice", [type.value]);
  } else if (type == MDLDeviceEngagement.NFC) {
    response = await _bridge.invokeMethod("engageDeviceNFC", []);
  } else if (type == MDLDeviceEngagement.QR && data != null) {
    response = await _bridge.invokeMethod("engageDeviceData", [data]);
  }
  var jsonObject = json.decode(response);
  return (
    DeviceEngagement.fromJson(jsonObject["deviceEngagement"]),
    DocReaderException.fromJson(jsonObject["error"]),
  );
}