nfc_manager

A Flutter plugin to use NFC. Supported on both Android and iOS.

Note

This plugin is still under development.

So please use with caution as there may be potential issues and breaking changes.

Feedback is welcome.

Setup

Android Setup

iOS Setup

Usage

Reading NDEF

NfcManager.instance.startNdefSession(
  alertMessageIOS: '[Any message displayed on the iOS system UI]',
  onNdefDiscovered: (NfcNdef ndef) {
    print(ndef);
  },
);

Writing NDEF

NfcManager.instance.startNdefSession(
  alertMessageIOS: '...',
  onNdefDiscovered: (NfcNdef ndef) async {
    if (!ndef.isWritable) {
      print('Tag is not ndef writable.');
      return;
    }

    final NdefMessage message = NdefMessage([
      NdefRecord.createTextRecord('Hello World'),
      NdefRecord.createUriRecord(Uri.parse('https://flutter.dev')),
      NdefRecord.createMimeRecord('plain/text', Uint8List.fromList('Hello World'.codeUnits)),
      NdefRecord.createExternalRecord([domain string], [type string], [data uint8list]),
    ]);

    try {
      await ndef.writeNdef(message);
    } catch (e) {
      // handle error
    }
  },
);

Reading Tag

NfcManager.instance.startTagSession(
  alertMessageIOS: '...',
  pollingOptions: {NfcTagPollingOption.iso14443, NfcTagPollingOption.iso15693, NfcTagPollingOption.iso18092},
  onTagDiscovered: (NfcTag tag) {
    print(tag);
    print(tag.ndef); // You can also read NDEF.
  },
);

Stop Session

NfcManager.instance.stopSession(
  alertMessageIOS: [success message string],
  errorMessageIOS: [error message string],
);

Libraries

nfc_manager