nfc_manager

A Flutter plugin for accessing the NFC features on Android and iOS.

Requirements

Android SDK Version >= 19 or iOS >= 12.0. (TODO: iOS 13.0)

Setup

Android

iOS

Handling the NFC Session

bool isAvailable = await NfcManager.instance.isAvailable();

if (!isAvailable) {
  print("The NFC features may not be supported on this device.");
  return;
}

NfcManager.instance.startSession(
  pollingOptions: ...,
  onDiscovered: (NfcTag tag) async {
    // Do something with an NfcTag instance.

    // Stop the session when the processing is completed.
    await NfcManager.instance.stopSession();
  },
);

Handling the NfcTag instance.

NfcTag is typically not used directly, but only to obtain an instance of a specific tag type. This plugin provides the following tag types:

Android Only

  • NdefAndroid
  • NfcAAndroid
  • NfcBAndroid
  • NfcFAndroid
  • NfcVAndroid
  • IsoDepAndroid
  • MifareClassicAndroid
  • MifareUltralightAndroid
  • NdefFormatableAndroid
  • NfcBarcodeAndroid

iOS Only

  • NdefIOS
  • MiFareIOS
  • FeliCaIOS
  • Iso15693IOS
  • Iso7618IOS

Abstraction between Android and iOS (sub packages)

Use from(NfcTag) static method to obtain an instance of a specific tag type. For example, to instantiate the Ndef:

import 'package:nfc_manager_ndef/nfc_manager_ndef.dart';

Ndef? ndef = Ndef.from(tag);

if (ndef == null) {
  print("The tag is not compatible with an NDEF.");
  return;
}

// Do something with an Ndef instance.

See the example directory or Real World App for more informations.