verify method

Future<bool> verify(
  1. List<int> template, {
  2. double far = 0.05,
})

Implementation

Future<bool> verify(List<int> template, {double far = 0.05}) async {
  ReceivePort receivePort = ReceivePort();
  Completer<bool> completer = Completer<bool>();
  if (_currentIsolate != null) {
    return false;
  }
  _currentIsolate = await Isolate.spawn((message) {
    terminate();
    initialize(far: far);
    Pointer<FTR_DATA> templateToCompare = calloc<FTR_DATA>();
    templateToCompare.ref.dwSize = template.length;
    templateToCompare.ref.pData = calloc<Uint8>(template.length);
    templateToCompare.ref.pData
        .asTypedList(template.length)
        .setAll(0, template);
    Pointer<Bool> bResult = calloc<Bool>();
    int verifyResult = _verify(nullptr, templateToCompare, bResult, 0);
    if (verifyResult != 0) {
      throw FutronicError(FutronicUtils.getErrorMessage(verifyResult));
    }
    message.send(bResult.value);
  }, receivePort.sendPort);

  _currentIsolate?.addErrorListener(receivePort.sendPort);
  receivePort.listen((message) {
    if (message is bool) {
      completer.complete(message);
    }
    if (message is List<String>) {
      completer.completeError(FutronicError(message[0]));
    }
  });
  await completer.future;
  receivePort.close();
  _currentIsolate?.kill();
  _currentIsolate = null;
  return await completer.future;
}