A Flutter plugin providing access to NFC features on Android and iOS.
- Add android.permission.NFC to your
AndroidManifest.xml.
- Add Near Field Communication Tag Reader Session Formats Entitlements to your entitlements.
- Add NFCReaderUsageDescription to your
Info.plist. - Add com.apple.developer.nfc.readersession.iso7816.select-identifiers to your
Info.plistas needed. - Add com.apple.developer.nfc.readersession.felica.systemcodes to your
Info.plistif you specifyNfcPollingOption.iso18092instartSession, otherwise an error will occur.
import 'package:nfc_manager/nfc_manager.dart';
// Check the availability of NFC on the current device.
NfcAvailability availability = await NfcManager.instance.checkAvailability();
if (availability != NfcAvailability.enabled) {
print('NFC may not be supported or may be temporarily disabled.');
return;
}
// Start the session.
NfcManager.instance.startSession(
pollingOptions: {NfcPollingOption.iso14443}, // You can also specify iso18092 and iso15693.
onDiscovered: (NfcTag tag) async {
// Do something with an NfcTag instance...
print(tag);
// Stop the session when no longer needed.
await NfcManager.instance.stopSession();
},
);An NfcTag instance is typically not used directly. Instead, convert it to a platform-specific tag class by calling that class's static method from.
import 'package:nfc_manager/nfc_manager.dart';
import 'package:nfc_manager_ndef/nfc_manager_ndef.dart';
final Ndef ndef = Ndef.from(tag);
if (ndef == null) {
print('This tag is not compatible with NDEF.');
return;
}
// Do something with an Ndef instance...
print(ndef);The following platform-specific tag classes are available:
NfcAAndroidNfcBAndroidNfcFAndroidNfcVAndroidIsoDepAndroidMifareClassicAndroidMifareUltralightAndroidNfcBarcodeAndroidNdefAndroidNdefFormatableAndroid
FeliCaIosMiFareIosIso15693IosIso7816IosNdefIos
Ndef(nfc_manager_ndef)FeliCa(nfc_manager_felica)- and more...