666marat666 / flutter-nfc-reader

Flutter NFC reader plugin for iOS and Android

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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" />

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.

About

Flutter NFC reader plugin for iOS and Android

License:MIT License


Languages

Language:Dart 30.5%Language:Kotlin 27.3%Language:Swift 19.9%Language:Ruby 19.5%Language:Objective-C 2.8%