nfc_manager 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 88

nfc_manager #

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

Setup #

Android Setup #

iOS Setup #

Usage #

Managing Session #

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

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

Manipulating 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.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)),
]);

// 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(...);

1.0.1 #

  • fix error on invoking transceive method.

1.0.0 #

  • added platform-specifc-tag operations.
  • removed NfcSessionType enum.
  • migrated 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.

example/README.md

nfc_manager_example #

Demonstrates how to use the nfc_manager plugin.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  nfc_manager: ^1.0.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:nfc_manager/nfc_manager.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
76
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
88
Learn more about scoring.

We analyzed this package on Jan 21, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health suggestions

Format lib/src/nfc_manager/nfc_manager.dart.

Run flutter format to format lib/src/nfc_manager/nfc_manager.dart.

Format lib/src/nfc_manager/nfc_ndef.dart.

Run flutter format to format lib/src/nfc_manager/nfc_ndef.dart.

Format lib/src/translator.dart.

Run flutter format to format lib/src/translator.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test