nfc_manager 0.5.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 87

nfc_manager #

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

Note #

This plugin is still under development.

So please use with caution as there may be potential issues and breaking changes.

Feedback is welcome.

Setup #

Android Setup #

iOS Setup #

Usage #

Reading NDEF #

NfcManager.instance.startNdefSession(
  alertMessageIOS: '[Any message displayed on the iOS system UI]',
  onNdefDiscovered: (NfcNdef ndef) {
    print(ndef);
  },
);

Writing NDEF #

NfcManager.instance.startNdefSession(
  alertMessageIOS: '...',
  onNdefDiscovered: (NfcNdef ndef) async {
    if (!ndef.isWritable) {
      print('Tag is not ndef writable.');
      return;
    }

    final NdefMessage message = NdefMessage([
      NdefRecord.createTextRecord('Hello World'),
      NdefRecord.createUriRecord(Uri.parse('https://flutter.dev')),
      NdefRecord.createMimeRecord('plain/text', Uint8List.fromList('Hello World'.codeUnits)),
      NdefRecord.createExternalRecord([domain string], [type string], [data uint8list]),
    ]);

    try {
      await ndef.writeNdef(message);
    } catch (e) {
      // handle error
    }
  },
);

Reading Tag #

NfcManager.instance.startTagSession(
  alertMessageIOS: '...',
  pollingOptions: {NfcTagPollingOption.iso14443, NfcTagPollingOption.iso15693, NfcTagPollingOption.iso18092},
  onTagDiscovered: (NfcTag tag) {
    print(tag);
    print(tag.ndef); // You can also read NDEF.
  },
);

Stop Session #

NfcManager.instance.stopSession(
  alertMessageIOS: [success message string],
  errorMessageIOS: [error message string],
);

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: ^0.5.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]
74
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]
87
Learn more about scoring.

We analyzed this package on Dec 13, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.1+4
  • Flutter: 1.12.13+hotfix.4

Health suggestions

Format lib/src/ndef.dart.

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

Format lib/src/nfc_manager.dart.

Run flutter format to format lib/src/nfc_manager.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