okadan / flutter-nfc-manager

A Flutter plugin for accessing the NFC features on Android and iOS.
https://pub.dev/packages/nfc_manager
MIT License
200 stars 131 forks source link
dart flutter flutter-plugin nfc

nfc_manager

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

Note: This plugin depends on NFCTagReaderSession (requires iOS 13.0 or later) and NfcAdapter#enableReaderMode (requires Android API level 19 or later).

Setup

Android Setup

iOS Setup

Usage

Handling Session

// Check availability
bool isAvailable = await NfcManager.instance.isAvailable();

// Start Session
NfcManager.instance.startSession(
  onDiscovered: (NfcTag tag) async {
    // Do something with an NfcTag instance.
  },
);

// Stop Session
NfcManager.instance.stopSession();

Handling Platform Tag

The following platform-tag-classes are available:

Obtain an instance by calling the factory constructor from on the class. For example:

Ndef? ndef = Ndef.from(tag);

if (ndef == null) {
  print('Tag is not compatible with NDEF');
  return;
}

// Do something with an Ndef instance

Please see the API Doc for more details.

Real-World-App

See this repo which is a Real-World-App demonstrates how to use this plugin.