flutter_nfc_reader 0.0.14

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

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

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

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. In order to stop a reading session you need to use stop function.

 Future<Null> NfcRead() async {
    String response;
    try {
      final String result = await FlutterNfcReader.read;
      if (result != null) {
        response = '';
      } else {
        response = result;
      }
    } on PlatformException {
      response = '';
    }
    setState(() {
      _nfcActive = true;
      _nfcData = response;
    });
  }

Stop NFC


  Future<Null> NfcStop() async {
    bool response;
    try {
      final bool result = await FlutterNfcReader.stop;
      response = !result;
    } on PlatformException {
      response = false;
    }
    setState(() {
      _nfcActive = response;
    });
  }

For better details look at the demo app.

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 _nfcActive = false;

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

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

    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await FlutterNfcReader.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

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

  Future<Null> startNFC() async {
    String response;
    try {
      final String result = await FlutterNfcReader.read;
      if (result != null) {
        response = '';
      } else {
        response = result;
      }
    } on PlatformException {
      response = '';
    }
    setState(() {
      _nfcActive = true;
      _nfcData = response;
    });
  }

  Future<Null> stopNFC() async {
    bool response;
    try {
      final bool result = await FlutterNfcReader.stop;
      response = result;
    } on PlatformException {
      response = false;
    }
    setState(() {
      _nfcActive = 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: Column(
                children: <Widget>[
                  new Text('Running on: $_platformVersion\n'),
                  new Text('NFC Status: $_nfcActive\n'),
                  new Text('NFC Data: $_nfcData\n'),
                  new FlatButton(
                    child: Text('Start NFC'),
                    onPressed: () {
                      startNFC();
                    },
                  ),
                  new FlatButton(
                    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.14

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.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
0.0.3 Jul 20, 2018 Go to the documentation of flutter_nfc_reader 0.0.3 Download flutter_nfc_reader 0.0.3 archive

All 12 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
66
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]
83
Learn more about scoring.

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

  • Dart: 2.0.0
  • pana: 0.11.8
  • Flutter: 0.5.7

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

Package is pre-v1 release.

While there is nothing inherently wrong with versions of 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.6 1.14.11
meta 1.1.5 1.1.6
sky_engine 0.0.99
typed_data 1.1.5 1.1.6
vector_math 2.0.6 2.0.8