capture static method

Future<NfcCard> capture({
  1. Duration? timeout,
  2. bool feedback = true,
})

Implementation

static Future<NfcCard> capture({Duration? timeout, bool feedback = true}) async {
  try {
    _stateStream.add(NfcPhase.initializing);
    if (_bridge != null) {
      _stateStream.add(NfcPhase.searching);
      await Future.delayed(const Duration(milliseconds: 500));
      final card = _bridge!.poll();
      _stateStream.add(NfcPhase.detected);
      return card;
    }
    _stateStream.add(NfcPhase.searching);
    final payload = await NfcNativeDriver.connectTag(waitTime: timeout, playSound: feedback);
    _stateStream.add(NfcPhase.detected);
    final card = NfcCard.create(payload);
    _stateStream.add(NfcPhase.completed);
    return card;
  } catch (e) {
    _stateStream.add(NfcPhase.failed);
    rethrow;
  } finally {
    if (_bridge == null) await NfcNativeDriver.closeSession();
  }
}