poll static method
- Duration? timeout,
- bool androidPlatformSound = true,
- bool androidCheckNDEF = true,
- String iosAlertMessage = "Hold your iPhone near the card",
- String iosMultipleTagMessage = "More than one tags are detected, please leave only one tag and try again.",
- bool readIso14443A = true,
- bool readIso14443B = true,
- bool readIso18092 = false,
- bool readIso15693 = true,
- bool probeWebUSBMagic = false,
Try to poll a NFC tag from reader.
If tag is successfully polled, a session is started.
The timeout parameter only works on Android & Web (default to be 20 seconds). On iOS it is ignored and decided by the OS.
On iOS, set iosAlertMessage to display a message when the session starts (to guide users to scan a tag),
and set iosMultipleTagMessage to display a message when multiple tags are found.
On Android, set androidPlatformSound to control whether to play sound when a tag is polled,
and set androidCheckNDEF to control whether check NDEF records on the tag.
The four boolean flags readIso14443A, readIso14443B, readIso18092, readIso15693 control the NFC technology that would be tried.
On iOS, setting any of readIso14443A and readIso14443B will enable iso14443 in pollingOption.
On Web, all parameters are ignored except timeout and probeWebUSBMagic.
If probeWebUSBMagic is set, the library will use the PROBE request to check whether the device supports our API (see FlutterNfcKitWeb for details).
Note: Sometimes NDEF check leads to error, and disabling it might help. If disabled, you will not be able to use any NDEF-related methods in the current session.
Implementation
static Future<NFCTag> poll({
Duration? timeout,
bool androidPlatformSound = true,
bool androidCheckNDEF = true,
String iosAlertMessage = "Hold your iPhone near the card",
String iosMultipleTagMessage =
"More than one tags are detected, please leave only one tag and try again.",
bool readIso14443A = true,
bool readIso14443B = true,
bool readIso18092 = false,
bool readIso15693 = true,
bool probeWebUSBMagic = false,
}) async {
// use a bitmask for compact representation
int technologies = 0x0;
// hardcoded bits, corresponding to flags in android.nfc.NfcAdapter
if (readIso14443A) technologies |= 0x1;
if (readIso14443B) technologies |= 0x2;
if (readIso18092) technologies |= 0x4;
if (readIso15693) technologies |= 0x8;
// iOS can safely ignore these option bits
if (!androidCheckNDEF) technologies |= 0x80;
if (!androidPlatformSound) technologies |= 0x100;
final String data = await _channel.invokeMethod('poll', {
'timeout': timeout?.inMilliseconds ?? POLL_TIMEOUT,
'iosAlertMessage': iosAlertMessage,
'iosMultipleTagMessage': iosMultipleTagMessage,
'technologies': technologies,
'probeWebUSBMagic': probeWebUSBMagic,
});
return NFCTag.fromJson(jsonDecode(data));
}