enrollTemplate method
Implementation
Future<FutronicEnrollResult> enrollTemplate() async {
ReceivePort receivePort = ReceivePort();
FutronicEnrollResult futronicEnrollResult = FutronicEnrollResult();
Completer<FutronicEnrollResult> completer =
Completer<FutronicEnrollResult>();
_currentIsolate = await Isolate.spawn((message) async {
BackgroundIsolateBinaryMessenger.ensureInitialized(
message[0] as RootIsolateToken);
DartPluginRegistrant.ensureInitialized();
terminate();
initialize(sendPort: message[1] as SendPort);
enrollX();
}, [RootIsolateToken.instance!, receivePort.sendPort], onError: sendPort);
_currentIsolate?.addErrorListener(receivePort.sendPort);
receivePort.listen((message) {
if (message is FutronicStatus) {
futronicStatusController.add(message);
}
if (message is FutronicStatus && message.quality != null) {
futronicEnrollResult.quality = message.quality!;
}
if (message is List<int>) {
futronicEnrollResult.enrollTemplate = message;
completer.complete(futronicEnrollResult);
}
if (message is List<String>) {
completer.completeError(FutronicError(message[0]));
}
});
await completer.future;
receivePort.close();
_currentIsolate?.kill();
_currentIsolate = null;
return await completer.future;
}