nfc_plus 1.0.0
nfc_plus: ^1.0.0 copied to clipboard
A high-performance, high-level NFC plugin for Flutter supporting Android, iOS, Web, and Desktop.
Nfc Plus Examples #
Modern High-Level API (Recommended) #
nfc_plus provides a high-level API through the Nfc class. This is the recommended way to interact with NFC tags.
One-Line Scan #
Start a session, wait for a tag, read it, and close the session automatically.
import 'package:nfc_plus/nfc_plus.dart';
try {
final tag = await Nfc.scan();
print("Detected tag: ${tag.uid}");
} catch (e) {
print("Error: $e");
}
Continuous Batch Scanning #
Useful for attendance or inventory management. Includes automatic duplicate filtering and cooldowns.
// Start continuous scanning
await Nfc.startContinuousScan(
ignoreDuplicates: true,
cooldown: Duration(seconds: 2),
);
// Listen to results
Nfc.tags.listen((tag) {
print("New tag detected: ${tag.uid}");
});
// Cancel when done
await Nfc.cancel();
Type-Safe Tag Interaction #
Interact with tags based on their hardware technology.
final tag = await Nfc.poll();
if (tag is MifareClassicTag) {
bool auth = await tag.authenticate(0, keyA: "FFFFFFFFFFFF");
if (auth) {
var data = await tag.readBlock(0);
print("Mifare Data: $data");
}
}
if (tag is Iso7816Tag) {
final resp = await tag.sendCommand("00A4040008A000000003000000");
print("APDU Response: $resp");
}
await Nfc.finish();
High-Level NDEF Writing #
Write complex NDEF data without manual byte manipulation.
// Write a Text record
await Nfc.write(Ndef.text("Hello World"));
// Write a WiFi configuration
await Nfc.write(Ndef.wifi(
ssid: "My_Network",
password: "mypassword",
));
// Write a batch of records
await Nfc.write([
Ndef.url("https://pub.dev"),
Ndef.email("contact@nfcplus.dev", subject: "Inquiry"),
]);
Low-Level Internal API #
If you need even more control, you can use the NfcPlusInternal class.
import 'package:nfc_plus/nfc_plus.dart';
// Check availability
NFCAvailability status = await NfcPlusInternal.nfcAvailability;
// Manual poll with custom technology flags
NFCTag tag = await NfcPlusInternal.poll(
readIso14443A: true,
readIso15693: false,
);
// Raw transceive
String response = await NfcPlusInternal.transceive("00B0950000");
// Always finish the session
await NfcPlusInternal.finish();