present static method

Future<Map<String, Stream>> present({
  1. IdentificationFlowOptions? options,
})

Present the identification flow

Returns a map with two streams:

  • 'results': Stream of IdentificationResult
  • 'errors': Stream of error messages (String)

For single-shot mode (keepIdentification = false):

  • The streams will emit once and close automatically

For continuous mode (keepIdentification = true):

  • The streams will emit multiple times until timeout or manual dismissal
  • Call dismiss to stop the flow manually

Example:

final streams = await IdentificationFlow.present();
streams['results']?.listen((result) {
  print('Identified: ${result.identified}');
  if (result.identified) {
    print('User: ${result.customId}');
  }
});
streams['errors']?.listen((error) {
  print('Error: $error');
});

Implementation

static Future<Map<String, Stream>> present({
  IdentificationFlowOptions? options,
}) async {
  HostedFlowBase.ensureListenerRegistered();

  // Clean up any existing streams
  HostedFlowBase.closeStreams();

  // Create new stream controllers
  HostedFlowBase.resultStreamController =
      StreamController<IdentificationResult>.broadcast();
  HostedFlowBase.errorStreamController = StreamController<String>.broadcast();

  final opts = options ?? const IdentificationFlowOptions();

  try {
    log('πŸš€ Starting identification flow...');

    final result = await HostedFlowBase.hostedFlowChannel.invokeMethod(
      'HostedFlow.present',
      opts.toMap(),
    );

    final success = result['success'] as bool? ?? false;
    if (!success) {
      final message = result['message'] as String? ?? 'Unknown error';
      log('❌ Failed to present flow: $message');
      HostedFlowBase.errorStreamController?.add(message);
      HostedFlowBase.closeStreams();
    } else {
      log('βœ… Flow presentation initiated');
    }
  } catch (e) {
    log('❌ Error presenting flow: $e');
    HostedFlowBase.errorStreamController?.add(e.toString());
    HostedFlowBase.closeStreams();
  }

  return {
    'results': HostedFlowBase.resultStreamController!.stream,
    'errors': HostedFlowBase.errorStreamController!.stream,
  };
}