nfc_manager

4.2.1

A Flutter plugin providing access to NFC features on Android and iOS.

Download archive

Readme

nfc_manager

A Flutter plugin providing access to NFC features on Android and iOS.

Setup

Android

iOS

Usage

Handling the Session

import 'package:nfc_manager/nfc_manager.dart';

// Check the availability of NFC on the current device.
NfcAvailability availability = await NfcManager.instance.checkAvailability();

if (availability != NfcAvailability.enabled) {
  print('NFC may not be supported or may be temporarily disabled.');
  return;
}

// Start the session.
NfcManager.instance.startSession(
  pollingOptions: {NfcPollingOption.iso14443}, // You can also specify iso18092 and iso15693.
  onDiscovered: (NfcTag tag) async {
    // Do something with an NfcTag instance...
    print(tag);

    // Stop the session when no longer needed.
    await NfcManager.instance.stopSession();
  },
);

Working with NfcTag

An NfcTag instance is typically not used directly. Instead, convert it to a platform-specific tag class by calling that class's static method from.

import 'package:nfc_manager/nfc_manager.dart';
import 'package:nfc_manager_ndef/nfc_manager_ndef.dart';

final Ndef ndef = Ndef.from(tag);

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

// Do something with an Ndef instance...
print(ndef);

The following platform-specific tag classes are available:

Android only

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

iOS only

  • FeliCaIos
  • MiFareIos
  • Iso15693Ios
  • Iso7816Ios
  • NdefIos

Cross-platform abstractions (separate packages)

Changelog

4.2.1

  • Fixes crash when re-opening the app from background.

4.2.0

  • Add Swift Package Manager support.
  • Bump dependencies.

4.1.1

  • Avoid iOS SDK version constraints caused by the addition of NFCReaderError.Code.

4.1.0

  • Deprecated NfcManager#isAvailable. Use NfcManager#checkAvailability instead.
  • Fix iOS background issue.
  • Add more NFCReaderError.Code for iOS.
  • Bump versions.
  • Update doc.

4.0.2

  • Update README.

4.0.1

  • Update package page.

4.0.0

Has many breaking changes.

  • Rename the following:
    • NfcA to NfcAAndroid
    • NfcB to NfcBAndroid
    • NfcF to NfcFAndroid
    • NfcV to NfcVAndroid
    • IsoDep to IsoDepAndroid
    • MifareClassic to MifareClassicAndroid
    • MifareUltralight to MifareUltralightAndroid
    • NdefFormatable to NdefFormatableAndroid
    • MiFare to MiFareIos
    • FeliCa to FeliCaIos
    • Iso15693 to Iso15693Ios
    • Iso7816 to Iso7816Ios
    • Options for startSession:
      • onError to onErrorIos
      • invalidateAfterFirstRead to invalidateAfterFirstReadIos
      • alertMessage to alertMessageIos
    • Options for stopSession:
      • alertMessage to alertMessageIos
      • errorMessage to errorMessageIos
  • Remove the following:
    • Ndef (Instead use the nfc_manager_ndef package or NdefAndroid / NdefIos)
    • timeout (Instead use the async getTimeout() method)
    • maxTransceiveLength (Instead use the async getMaxTransceiveLength() method)
    • NfcError (Instead use the NfcReaderSessionErrorIos)
    • NfcErrorType (Instead use the NfcReaderErrorCodeIos)
  • Add the following:
    • ndef_record.dart library that provides access to ndef_record package.
    • nfc_manager_android.dart library that provides access to Android API.
    • nfc_manager_ios.dart library that provides access to iOS API.
    • async setTimeout() method.
    • noPlatformSoundsAndroid option to startSession method.
  • Upgrade Flutter.
  • Update README.

3.5.1

  • Make compatible for Kotlin 2.1.0

3.5.0

  • Upgrade Flutter.
  • Fix analyze issues.

3.4.0

  • Fix iOS background isolate issue.
  • Add namespace to Gradle for Android.
  • Rebuild projects on Flutter stable channel.

3.3.0

  • Added invalidateAfterFirstRead argument to startSession. This enables restartPolling on iOS.

3.2.0

  • Fix build issues.

3.1.1

  • Upgrade kotlin version.

3.1.0

  • Fix Null-Safety related issues. The following properties are now nullable.
    • IsoDep#hiLayerResponse
    • IsoDep#historicalBytes
    • Iso7816#historicalBytes
    • Iso7816#applicationData
    • MiFare#historicalBytes

3.0.0+2

  • Update doc.

3.0.0+1

  • Flutter format.

3.0.0

  • Upgrade to null safety.

2.0.3

  • Fix type conversion errors in FeliCa#readWithoutEncryption and FeliCa#requestServiceV2.

2.0.2

  • Fix a bug in calling FeliCa.sendFeliCaCommand method.

2.0.1+1

  • Update README.

2.0.1

  • Fix an error when initializing plugin for non-NFC Android devices.

2.0.0+2

  • Update doc.
  • Flutter format.

2.0.0+1

  • Update doc.

2.0.0

Has many breaking changes.

  • Remove startNdefSession and NdefDiscoveredCallback.
  • Rename startTagSession to startSession.
  • Rename TagPollingOption to NfcPollingOption.
  • Rename NfcSessionError to NfcError.
  • Rename NfcSessionErrorType to NfcErrorType.
  • Rename TagDiscoveredCallback to NfcTagCallback.
  • Rename NfcSessionErrorCallback to NfcErrorCallback.
  • Rename ISO15693 to Iso15693.
  • Rename ISO7816 to Iso7816.
  • Rename fromTag to from. (e.g. MiFare.fromTag(tag) -> MiFare.from(tag))
  • Add NdefTypeNameFormat enum.
  • Add NdefFormatable, MifareClassic and MifareUltralight classes.
  • Add Ndef#read method.
  • Add command-implementations for FeliCa and Iso15693.
  • Upgrade flutter environment.

1.3.2+4

  • Update README.

1.3.2+3

  • Update README.

1.3.2+2

  • Update README.

1.3.2+1

  • Update README.

1.3.2

  • Fix crash on Ndef write and writeLock error.

1.3.1

  • Fix a bug where the error callback was not called.

1.3.0

  • Add callback to handle error from session.

1.2.0

  • Make discovered callback async.

1.1.0+1

  • Update readme.

1.1.0

  • Add constants.
  • Fix misspelled name.
  • Fix xcode build warning.
  • Increase the Flutter SDK requirement to ^1.10.0.

1.0.1

  • Fix error on invoking transceive method.

1.0.0

  • Add platform-specifc-tag operations.
  • Remove NfcSessionType enum.
  • Migrate to pubspec platforms manifest.
  • More consistent naming.

0.5.1

  • Update flutter project files.
  • Additional fix for migration to AndroidX.

0.5.0

  • Migrate to AndroidX.

0.4.0+2

  • Fix typo on README

0.4.0+1

  • Update README

0.4.0

  • Rename NfcNdef#cachedNdef to NfcNdef#cachedMessage.
  • Add NfcSessionType enum.
  • Add NfcTagPollingOption enum.

0.3.0

  • Add NdefRecord#createMimeRecord.
  • Add optional parameters alertMessageIOS and errorMessageIOS displayed in iOS system UI.
  • Fix error on deserializing null message on dart side.

0.2.0

  • Split startSession into startNdefSession and startTagSession.
  • Improve doc.

0.1.1

  • Fix crash on serializing nil message on ios side.
  • Add example project.
  • Improve doc.

0.1.0+2

  • Improve doc.

0.1.0+1

  • Improve doc.

0.1.0

  • Add iOS 13 features.

0.0.1

  • Initial release.

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add nfc_manager
pubspec.yaml
name: nfc_manager
description: A Flutter plugin providing access to NFC features on Android and iOS.
repository: https://github.com/okadan/flutter-nfc-manager
version: 4.2.1

environment:
  sdk: ^3.11.4
  flutter: '>=3.3.0'

dependencies:
  flutter:
    sdk: flutter
  meta: ^1.17.0
  ndef_record: ^1.4.2

dev_dependencies:
  flutter_lints: ^6.0.0
  pigeon: ^26.3.3

flutter:
  plugin:
    platforms:
      android:
        package: dev.flutter.plugins.nfcmanager
        pluginClass: NfcManagerPlugin
      ios:
        pluginClass: NfcManagerPlugin

Version history

VersionPublishedArchiveSHA-256
0.0.1On demandDownloadeccc758f…dfa1ea
0.1.0On demandDownloade2db25c8…fc1f40
0.1.0+1On demandDownload06dc7d54…bba8ad
0.1.0+2On demandDownload542e6e18…d4774a
0.1.1On demandDownloaddf3bcc98…6e3ec2
0.2.0On demandDownload13a27627…0de2d8
0.3.0On demandDownload30b25d0c…1050ef
0.4.0On demandDownload78ee9d3a…b00751
0.4.0+1On demandDownload1a692e26…dc2d45
0.4.0+2On demandDownload5ba9255d…d63307
0.5.0On demandDownloadf9bdbaa2…914297
0.5.1On demandDownloadcdc01186…ed721f
1.0.0-devOn demandDownloadbf79b0e3…e50e68
1.0.0-dev.1On demandDownload5718e0c3…882d36
1.0.0-dev.2On demandDownload6aef44d1…e9eebb
1.0.0-dev.3On demandDownload592a0a74…fb0d58
1.0.0-dev.4On demandDownloada4ee5a86…6da4a9
1.0.0-dev.5On demandDownload4267ef5d…9a2e55
1.0.0-dev.6On demandDownload38b4fe27…ef3864
1.0.0-dev.7On demandDownload5fa70a38…aff9e5
1.0.0On demandDownload5a64dbbb…a7753b
1.0.1On demandDownload97bcad18…e7e63b
1.1.0On demandDownloadf4d5e1d0…17d400
1.1.0+1On demandDownload7639a692…890af8
1.2.0On demandDownloaddaf669ba…9e87eb
1.3.0-devOn demandDownload6d89b714…7198e3
1.3.0-dev+1On demandDownloadb784ba26…e4bb57
1.3.0On demandDownloadfe31802e…3751eb
1.3.1On demandDownloadbfdc66d2…8dc54a
1.3.2On demandDownload5901fbff…276e17
1.3.2+1On demandDownloadd204a894…ab122b
1.3.2+2On demandDownload5e9d8fb8…294a1a
1.3.2+3On demandDownload76d787f3…6a2282
1.3.2+4On demandDownload8a5ff556…cbd6c5
1.4.0-devOn demandDownloade3c3772f…944fe1
1.4.0-dev+1On demandDownloadd5465157…9a477c
1.4.0-dev+2On demandDownload23fa886f…33181d
1.4.0-dev+3On demandDownloadce593986…534027
1.4.0-dev+4On demandDownload1ffc5002…a9f433
2.0.0-devOn demandDownload5ca3b483…f6e96f
2.0.0On demandDownload9fc4899b…64628f
2.0.0+1On demandDownload788612d5…fd1fb4
2.0.0+2On demandDownload54bc39d5…84a84f
2.0.1On demandDownload4d632ced…aa04af
2.0.1+1On demandDownload8fe2eabf…3ec89c
2.0.2On demandDownload9a3ebae0…19bcc0
2.0.3On demandDownloade25b9585…35512f
3.0.0On demandDownloadf06b3cd8…3d08e7
3.0.0+1On demandDownload92976b42…b3c7a6
3.0.0+2On demandDownloadb6d62464…529510
3.1.0On demandDownload1571c62a…4417ac
3.1.1On demandDownloade967e5b0…25baf0
3.2.0On demandDownloadcff1e59e…3b0f4a
3.3.0On demandDownloadd6a4cc6a…970baf
3.4.0On demandDownload25b3ed2a…7f08c5
3.5.0On demandDownloadf5be75e9…ff8c59
3.5.1On demandDownload071faa6e…03c326
4.0.0-devOn demandDownloade4290103…262398
4.0.0On demandDownload61f8d7ec…d5ac38
4.0.1On demandDownload536c1352…b2fb2d
4.0.2On demandDownload164cc022…57f676
4.1.0On demandDownload4977eec6…3541aa
4.1.1On demandDownload24c78b0e…866879
4.2.0On demandDownloada88e174e…3ba6fa
4.2.1Cached · Upstream SHA-256 matchedDownload1b8d3788…151fe6

Dependencies

flutter { "sdk": "flutter" }

meta "^1.17.0"

ndef_record "^1.4.2"