nfc_manager 4.0.2
nfc_manager: ^4.0.2 copied to clipboard
A Flutter plugin for accessing the NFC features on Android and iOS.
nfc_manager #
A Flutter plugin for accessing the NFC features on Android and iOS.
Setup #
Android #
- Ensure that
minSdkVersion
is set to 19 or higher. - Add android.permission.NFC to your
AndroidManifest.xml
.
iOS #
- Ensure that the iOS Deployment Target is set to 13.0 or higher.
- 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.plist
as needed. - Add com.apple.developer.nfc.readersession.felica.systemcodes to your
Info.plist
if you specifyNfcPollingOption.iso18092
instartSession
, otherwise an error will occur.
Usage #
Handling the Session #
import 'package:nfc_manager/nfc_manager.dart';
// Check is NFC is available.
bool isAvailable = await NfcManager.instance.isAvailable();
// 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();
},
);
Working with NfcTag #
An NfcTag
instance is typically not used directly. Instead, it's converted into a vendor-specific tag instance by calling a static method from(tag)
.
import 'package:nfc_manager/nfc_manager.dart';
import 'package:nfc_manager_ndef/nfc_manager_ndef.dart';
final ndef = Ndef.from(tag);
if (ndef == null) {
print('The tag is not compatible with NDEF.');
return;
}
// Do something with an Ndef instance...
print(ndef);
The following vendor-specific tag classes are available:
Android only
NfcAAndroid
NfcBAndroid
NfcFAndroid
NfcVAndroid
IsoDepAndroid
MifareClassicAndroid
MifareUltralightAndroid
NfcBarcodeAndroid
NdefAndroid
NdefFormatableAndroid
iOS only
FeliCaIos
MiFareIos
Iso15693Ios
Iso7816Ios
NdefIos
Cross-Platform Abstractions (External Packages)
Ndef
(nfc_manager_ndef)FeliCa
(nfc_manager_felica)- and more...