flutter_nfc_reader 0.0.15

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 79

Flutter NFC Reader

A new flutter plugin to help developers looking to use internal hardware inside iOS or Android devices for reading NFC tags.

The system activate a pooling reading session that stops automatically once a tag has been recognised. You can also trigger the stop event manually using a dedicated function.

How to use

Android setup

Add those two lines to your AndroidManifest.xml on the top

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

and add this in your .MainActivity just below the other intent-filter:

<intent-filter>
  <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
  <category android:name="android.intent.category.DEFAULT"/>
  <data android:mimeType="text/plain" />
</intent-filter>

Attention the mimeType should be the right one for the expected type of NFC you are going to read.

iOS Setup

Atm only Swift based Flutter project are supported.

  • Enable Capabilities / Near Field Communication Tag Reading.
  • Info.plist file, add Privacy - NFC Scan Usage Description with string value NFC Tag.

Read NFC

This function will return a promise when a read occurs, till that very moment the reading session is open. The promise will return a map with <String, dynamic>. The map will have inside status or data key. In order to stop a reading session you need to use stop function.

Future<void> startNFC() async {
    String response;
    bool reading = true;

    try {
      response = await FlutterNfcReader.read;
    } on PlatformException {
      response = '';
      reading = false;
    }
    setState(() {
      _nfcReading = reading;
      _nfcData = response;
    });
  }

Stop NFC


  Future<void> stopNFC() async {
    bool response;
    try {
      final bool result = await FlutterNfcReader.stop;
      response = result;
    } on PlatformException {
      response = false;
    }
    setState(() {
      _nfcReading = response;
    });
  }

For better details look at the demo app.

Extra

FlutterNfcReader.read() has an optional parameter, only for iOS, called instruction. You can pass a String that contains information to be shown in the modal screen.

Getting Started

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

0.0.14

  • Stable iOS version.
  • Fix issue with importing with Cocoapods.

0.0.5

  • iOS fix support for static modules.

0.0.4

  • iOS add extra details on readme for usage.

0.0.3

  • Flutter required min version is now 0.5.5 as latest stable.

0.0.2

  • Name refactoring for functions, more descriptive and synteic.
  • On read event force stopping the pooling in background to optimize usage.

0.0.1

  • First release, android untested.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter_nfc_reader/flutter_nfc_reader.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String _nfcData = '';
  bool _nfcReading = false;

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;

    try {
      platformVersion = await FlutterNfcReader.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  Future<void> startNFC() async {
    String response;
    bool reading = true;

    try {
      response = await FlutterNfcReader.read;
      reading = false;
    } on PlatformException {
      response = '';
      reading = false;
    }
    setState(() {
      _nfcReading = reading;
      _nfcData = response;
    });
  }

  Future<void> stopNFC() async {
    bool response;
    try {
      final bool result = await FlutterNfcReader.stop;
      response = result;
    } on PlatformException {
      response = false;
    }
    setState(() {
      _nfcReading = response;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
          appBar: new AppBar(
            title: const Text('Plugin example app'),
          ),
          body: new SafeArea(
            top: true,
            bottom: true,
            child: new Center(
              child: ListView(
                children: <Widget>[
                  new SizedBox(
                    height: 10.0,
                  ),
                  new Text(
                    'Running on: $_platformVersion\n',
                    textAlign: TextAlign.center,
                  ),
                  new Text(
                    'NFC is Reading: $_nfcReading\n',
                    textAlign: TextAlign.center,
                  ),
                  new Text(
                    'NFC Data: $_nfcData\n',
                    textAlign: TextAlign.center,
                  ),
                  new RaisedButton(
                    child: Text('Start NFC'),
                    onPressed: () {
                      startNFC();
                    },
                  ),
                  new RaisedButton(
                    child: Text('Stop NFC'),
                    onPressed: () {
                      stopNFC();
                    },
                  ),
                ],
              ),
            ),
          )),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_nfc_reader: ^0.0.15

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages 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_reader/flutter_nfc_reader.dart';
  
Version Uploaded Documentation Archive
0.0.15 Oct 5, 2018 Go to the documentation of flutter_nfc_reader 0.0.15 Download flutter_nfc_reader 0.0.15 archive
0.0.14 Jul 22, 2018 Go to the documentation of flutter_nfc_reader 0.0.14 Download flutter_nfc_reader 0.0.14 archive
0.0.12 Jul 22, 2018 Go to the documentation of flutter_nfc_reader 0.0.12 Download flutter_nfc_reader 0.0.12 archive
0.0.11 Jul 22, 2018 Go to the documentation of flutter_nfc_reader 0.0.11 Download flutter_nfc_reader 0.0.11 archive
0.0.9 Jul 22, 2018 Go to the documentation of flutter_nfc_reader 0.0.9 Download flutter_nfc_reader 0.0.9 archive
0.0.8 Jul 22, 2018 Go to the documentation of flutter_nfc_reader 0.0.8 Download flutter_nfc_reader 0.0.8 archive
0.0.7 Jul 22, 2018 Go to the documentation of flutter_nfc_reader 0.0.7 Download flutter_nfc_reader 0.0.7 archive
0.0.6 Jul 22, 2018 Go to the documentation of flutter_nfc_reader 0.0.6 Download flutter_nfc_reader 0.0.6 archive
0.0.5 Jul 22, 2018 Go to the documentation of flutter_nfc_reader 0.0.5 Download flutter_nfc_reader 0.0.5 archive
0.0.4 Jul 21, 2018 Go to the documentation of flutter_nfc_reader 0.0.4 Download flutter_nfc_reader 0.0.4 archive

All 13 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
62
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
79
Learn more about scoring.

We analyzed this package on Oct 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4
  • Flutter: 0.9.5

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance suggestions

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

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

Dependencies

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