nfc_manager 0.0.1 nfc_manager: ^0.0.1 copied to clipboard
A Flutter plugin to use NFC features. Supported on Android/iOS.
nfc_manager #
A Flutter plugin to use NFC features. Supported on both Android/iOS.
Note: This plugin is still under development, and some APIs might not be available yet.
Usage #
import 'package:nfc_manager/nfc_manager.dart';
import 'package:nfc_manager/nfc_ndef.dart';
// Start a session and register onTagDiscovered callback.
await NfcManager.instance.startSession(
onTagDiscovered: (NfcTag tag) async {
if (tag.ndef == null) {
print('Tag is not NDEF formattable');
return;
}
if (tag.ndef.cachedNdefMessage == null) {
print('NDEF is in INITIALIZED state');
return;
}
// Now you can get an NDEF Message that cached at the time of discovery.
NfcNdefMessage cachedMessage = tag.ndef.cachedNdefMessage;
// Create an NDEF Message you want to write.
NfcNdefMessage message = NfcNdefMessage([
NfcNdefRecord.createText('Hello World'),
]);
// Write an NDEF Message on this tag.
await tag.ndef.writeNdef(message);
// We can also refer to tag-specific data.
// This data will be used by this plugin in the future.
Map<String, dynamic> data = tag.additinalData;
// Should stop a session at the appropriate time.
await NfcManager.instance.stopSession();
},
);