from static method

Ndef? from(
  1. NfcTag tag
)

Returns an instance for tag, or null when the tag does not hold NDEF.

Also null when the session set skipNdefCheck, which skips the probe that fills this in.

Implementation

static Ndef? from(NfcTag tag) {
  final android = tag.data.ndefAndroid;
  if (android != null) {
    return Ndef._(
      tag.data.handle,
      isWritable: android.isWritable,
      maxSize: android.maxSize,
      cachedMessage: android.cachedMessage == null ? null : ndefMessageFromWire(android.cachedMessage!),
    );
  }

  final ios = tag.data.ndefIos;
  if (ios != null) {
    return Ndef._(
      tag.data.handle,
      // CoreNFC reports a status rather than a flag; only readWrite can be written.
      isWritable: ios.status == NdefStatusPigeon.readWrite,
      maxSize: ios.capacity,
      cachedMessage: ios.cachedMessage == null ? null : ndefMessageFromWire(ios.cachedMessage!),
    );
  }

  return null;
}