flutter_nfc_plugin 0.0.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 75

Flutter NFC plugin #

The Flutter NFC plugin allows you to read NFC state and tags

Supported Platforms #

  • Android

Installing #

Add to pubspec.yaml:

      url: git://github.com/dukhanov/flutter-nfc-plugin.git
      ref: master

Add NFC permissions to Android package's manifest file:

<uses-permission android:name="android.permission.NFC" />
<uses-feature android:name="android.hardware.nfc" />

To be able to start the app within an NFC tag scanned Add such intent filter to Android package's manifest file inside of the Main activity section:

    <action android:name="android.nfc.action.TECH_DISCOVERED" />
    <action android:name="android.nfc.action.NDEF_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="*" />

And nfc_tech_filter.xml to the android/app/src/main/res/xml folder (create if not exist). See example project

File: nfc_tech_filter.xml
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">

Add such metadata to Android package's manifest file inside of the Main activity section:

<meta-data android:name="android.nfc.action.TECH_DISCOVERED" android:resource="@xml/nfc_tech_filter" />

Example of usage #

Check NFC state: #

NfcPlugin nfcPlugin = NfcPlugin();
try {
  final NfcState _nfcState = await nfcPlugin.nfcState;
  print('NFC state is $_nfcState');
} on PlatformException {
  print('Method "NFC state" exception was thrown');

Check NFC message which was used to start the app: #

NfcPlugin nfcPlugin = NfcPlugin();
try {
  final NfcEvent _nfcEventStartedWith = await nfcPlugin.nfcStartedWith;
  print('NFC event started with is ${_nfcEventStartedWith.toString()}');
  if (_nfcEventStartedWith != null) {
    setState(() {
      nfcMessageStartedWith = _nfcEventStartedWith.message;
} on PlatformException {
  print('Method "NFC event started with" exception was thrown');

Read NFC tags subscribe: #

NfcPlugin nfcPlugin = NfcPlugin();
nfcPlugin.onNfcMessage.listen((NfcEvent event) {
if (event.error.isNotEmpty) {
  print('NFC read error: ${event.error}');
} else {
  print('NFC read successful');

See more at: example project

0.0.5 #

  • Fixed: can't read tag id if the message is null

0.0.4 #

  • Upgraded to support AndroidX

0.0.3 #

  • Adapt with Flutter 1.6

0.0.2 #

  • Fixed: podspec for iOS

0.0.1 #

  • Added: an ability to read NFC tags
  • Added: an ability to read NFC state
  • Added: getting NFC message in case the app was started within an NFC tag


Flutter NFC plugin example #

Demonstrates how to use the nfc_plugin plugin.

Note: the plugin is currently supported Android platform only

Getting Started #

For help getting started with Flutter, view flutter online documentation

Use this package as a library

1. Depend on it

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

  flutter_nfc_plugin: ^0.0.5

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:flutter_nfc_plugin/models/nfc_event.dart';
import 'package:flutter_nfc_plugin/models/nfc_message.dart';
import 'package:flutter_nfc_plugin/models/nfc_state.dart';
import 'package:flutter_nfc_plugin/nfc_plugin.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.8

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.


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