read method

dynamic read()

Implementation

read() async {
  bool stopPoll = false;
  while (
      _listeners != null && _listeners!.isNotEmpty && !polling && !stopPoll) {
    try {
      Log().debug('NFC READ: Polling...');
      polling = true;
      NFCTag tag = await FlutterNfcKit.poll();
      Log().debug('NFC: Done Polling...');

      // read the tag
      String? result = await readNFCTag(tag);

      if (result != null) {
        // ??
        await FlutterNfcKit.finish(iosAlertMessage: "Finished!");

        // debug
        Log().debug('NFC: Read Result'
            '\nID: ${tag.id}'
            '\nStandard: ${tag.standard}'
            '\nType: ${tag.type}'
            '\nATQA: ${tag.atqa}'
            '\nSAK: ${tag.sak}'
            '\nHistorical Bytes: ${tag.historicalBytes}'
            '\nProtocol Info: ${tag.protocolInfo}'
            '\nApplication Data: ${tag.applicationData}'
            '\nHigher Layer Response: ${tag.hiLayerResponse}'
            '\nManufacturer: ${tag.manufacturer}'
            '\nSystem Code: ${tag.systemCode}'
            '\nDSF ID: ${tag.dsfId}'
            '\nNDEF Available: ${tag.ndefAvailable}'
            '\nNDEF Type: ${tag.ndefType}'
            '\nNDEF Writable: ${tag.ndefWritable}'
            '\nNDEF Can Make Read Only: ${tag.ndefCanMakeReadOnly}'
            '\nNDEF Capacity: ${tag.ndefCapacity}'
            '\nTransceive Result:\n$result');

        // format result
        if (result.contains("text=")) {
          result = result.substring(result.indexOf('text=') + 5);
        }

        // notify
        notifyListeners(Payload(id: tag.id, message: result));
      } else {
        Log().debug('NFC: result is null');
      }
    } catch (e) {
      if (e.toString() == '408' && e.toString() == 'Polling tag timeout') {
        Log().debug('NFC: ...Timeout');
      } else if (e.toString() == '409') {
        Log().debug('Polling Loop Ended via result or cancel');
        stopPoll = true;
      } else {
        Log().debug('NFC ERROR: $e');
      }
    }
    polling = false;
  }
}