Skip to content

A Flutter plugin to manage the NFC features. Supported on both Android and iOS.

License

Notifications You must be signed in to change notification settings

adminant/flutter_nfc_manager

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nfc_manager

A Flutter plugin to manage the NFC features. Supported on both Android and iOS.

Setup

Android Setup

iOS Setup

Usage

Managing Session

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

// Start session and register callback.
NfcManager.instance.startTagSession(onDiscovered: (NfcTag tag) {
  // Manipulating tag
});

// Stop session and unregister callback.
NfcManager.instance.stopSession();

Manipulating NDEF

// Obtain an Ndef instance from tag
Ndef ndef = Ndef.fromTag(tag);

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

// Get an NdefMessage instance cached at discovery time
NdefMessage message = ndef.cachedMessage;

// Create an NdefMessage instance you want to write.
NdefMessage messageToWrite = NdefMessage([
  NdefRecord.createText('Hello'),
  NdefRecord.createUri(Uri.parse('https://flutter.dev')),
  NdefRecord.createMime('text/plain', Uint8List.fromList('Hello'.codeUnits)),
  NdefRecord.createExternal('mydomain', 'mytype', Uint8List.fromList('mydata'.codeUnits)),
]);

if (!ndef.isWritable) {
  print('Tag is not ndef writable');
  return;
}

// Write an NdefMessage
try {
  await ndef.write(messageToWrite);
} catch (e) {
  // handle error
  return;
}

Manipulating Platform-Specific-Tag

The following platform-specific-tag classes are available:

iOS

  • MiFare
  • FeliCa
  • ISO15693
  • ISO7816

Android

  • NfcA
  • NfcB
  • NfcF
  • NfcV
  • IsoDep

Example

MiFare miFare = MiFare.fromTag(tag);

if (miFare == null) {
  print('MiFare is not available on this tag');
  return;
}

Uint8List response = await miFare.sendMiFareCommand(...);

Example

A simple example app can be found in example folder.

Real-World example apps can be found in Google Play and App Store.

About

A Flutter plugin to manage the NFC features. Supported on both Android and iOS.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 49.1%
  • Swift 29.6%
  • Kotlin 18.8%
  • Ruby 2.0%
  • Objective-C 0.5%