nfc_manager 1.0.0-dev.4 copy "nfc_manager: ^1.0.0-dev.4" to clipboard
nfc_manager: ^1.0.0-dev.4 copied to clipboard

outdated

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

nfc_manager #

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

Setup #

Android Setup #

iOS Setup #

Usage #

Starting and Stopping Session #

// Start session and register callback.
NfcManager.instance.startTagSession(
  alertMessageIOS: '...',
  pollingOptions: {TagPollingOption.iso14443, TagPollingOption.iso18092, TagPollingOption.iso15693},
  onDiscovered: (NfcTag tag) {
    // Manipulating tag
  },
);

// Stop session and unregister callback.
NfcManager.instance.stopSession(
  alertMessageIOS: '...',
  errorMessageIOS: '...',
);

Reading and Writing NDEF #

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

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

// Read an NdefMessage object cached at discovery time
print(ndef.cachedMessage);

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

NdefMessage messageToWrite = NdefMessage([
  NdefRecord.createTextRecord('Hello'),
  NdefRecord.createUriRecord(Uri.parse('https://flutter.dev')),
  NdefRecord.createMimeRecord('text/plain', Uint8List.fromList('Hello'.codeUnits)),
  NdefRecord.createExternalRecord('mydomain', 'mytype', Uint8List.fromList('mydata'.codeUnits)),
]);

// 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(...);
411
likes
0
pub points
98%
popularity

Publisher

verified publisherokadan.net

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

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on nfc_manager