All Projects → semlette → Nfc_in_flutter

semlette / Nfc_in_flutter

Licence: mit
Cross-platform flutter plugin for reading and writing NFC tags. Not maintained anymore.

Programming Languages

dart
5743 projects

Projects that are alternatives of or similar to Nfc in flutter

Mifareonetool
A GUI Mifare Classic tool on Windows(停工/最新版v1.7.0)
Stars: ✭ 404 (+380.95%)
Mutual labels:  nfc
Open Home Automation
Open Home Automation with Home Assistant, ESP8266/ESP32 and MQTT
Stars: ✭ 820 (+876.19%)
Mutual labels:  nfc
Emv Nfc Paycard Enrollment
A Java library used to read and extract data from NFC EMV credit cards (Android/PCSC).
Stars: ✭ 1,009 (+1101.19%)
Mutual labels:  nfc
Nfcgate
An NFC research toolkit application for Android
Stars: ✭ 425 (+405.95%)
Mutual labels:  nfc
Smarthotel360 Mobile
SmartHotel360 Mobile
Stars: ✭ 535 (+536.9%)
Mutual labels:  nfc
Didicallcar
这是我自己做的一个类似滴滴打车的Android出行项目,主要针对滴滴等出行平台一直饱受质疑的“人车不符”问题,以及当前越发火热的或计划和出海战略,给出行项目增加了下面几个功能: 1. RFID识别验证功能:在司机证件或者车内识别硬件嵌入RFID识别芯片,乘客使用手机读取到芯片信息,并且通过网络发送到出行平台数据库进行验证(我用JNI加了一个C语言的MD5加密算法对识别到的信息进行了加密)。如果不是合规的“人”或“车”,则不能完成订单并向平台或监管单位汇报当前位置。(为了方便读者测试,可以使用手机读取任何一个加密或非加密RFID芯片,比如银行卡、公交卡等,我在代码中的验证前阶段把芯片信息都换成我自己的司机信息,确保读者测试时可以收到服务器的回复) 2. 海外版功能:点击切换当前语言。 3. 司机证件号码识别功能:读取司机证件上的证件号码,也可以用来与出行平台数据库的接单司机信息进行。I complete this whole project on my own . Including Android application programming,web server ( Apache + PHP + MySQL), and UI. 1.Map route planing。You can use mobile phone choose pick up & destination address,application provide address name hint and draw optimized route for user , then call car for you. 2.RFID authentication function:User can use application to scan driver license or other RFID hardware, then use NDK MD5 algorithm encrypt RFID number, and send it to Web Server Database, check with driver information and authenticate ID number , if ID number coherent with driver info , send back driver information to User and continue call car order . record user location and alert if ID not coherent. 3.Driver License Number Recognition : Application can recognize driver license digit number ,and also can send to web server for authentication & feed back result to user.
Stars: ✭ 935 (+1013.1%)
Mutual labels:  nfc
Tretjapannfcreader
NFC (FeliCa) Reader for iOS 13 Core NFC / 日本の NFC、FeliCa カード向けリーダーライブラリ(iOS 13.0 以降 Core NFC)交通系IC(Suica、PASMO など)、楽天Edy、nanaco、WAON など、運転免許証、マイナンバーカードの読み取り
Stars: ✭ 323 (+284.52%)
Mutual labels:  nfc
Chameleonmini
The ChameleonMini is a versatile contactless smartcard emulator compliant to NFC. The ChameleonMini was developed by https://kasper-oswald.de. The device is available at https://shop.kasper.it. For further information see the Getting Started Page https://rawgit.com/emsec/ChameleonMini/master/Doc/Doxygen/html/_page__getting_started.html or the Wiki tab above.
Stars: ✭ 1,133 (+1248.81%)
Mutual labels:  nfc
React Native Nfc Manager
React Native NFC module for Android & iOS
Stars: ✭ 668 (+695.24%)
Mutual labels:  nfc
Libnfc
Platform independent Near Field Communication (NFC) library
Stars: ✭ 997 (+1086.9%)
Mutual labels:  nfc
Nfcpassportreader
NFCPassportReader for iOS 13
Stars: ✭ 458 (+445.24%)
Mutual labels:  nfc
Homepwn
HomePwn - Swiss Army Knife for Pentesting of IoT Devices
Stars: ✭ 526 (+526.19%)
Mutual labels:  nfc
React Native Felica
React Native Felica module for Android
Stars: ✭ 31 (-63.1%)
Mutual labels:  nfc
Vsmartcard
umbrella project for emulation of smart card readers or smart cards
Stars: ✭ 404 (+380.95%)
Mutual labels:  nfc
Mifare Classic Toolkit
RFID / NFC :: Mifare Classic 1k info and tools
Stars: ✭ 46 (-45.24%)
Mutual labels:  nfc
Nfcpy
A Python module to read/write NFC tags or communicate with another NFC device.
Stars: ✭ 360 (+328.57%)
Mutual labels:  nfc
Proxmark3
RRG / Iceman repo, the most totally wicked repo around if you are into Proxmark3
Stars: ✭ 901 (+972.62%)
Mutual labels:  nfc
Waterdrink
💧 Simple water drinking reminder application based on MVP architecture.
Stars: ✭ 68 (-19.05%)
Mutual labels:  nfc
React Native Nfc Ios
Easy to use CoreNFC for React Native
Stars: ✭ 59 (-29.76%)
Mutual labels:  nfc
Desfire Tools For Android
Open source MIFARE DESFire EV1 NFC library for Android
Stars: ✭ 38 (-54.76%)
Mutual labels:  nfc

nfc_in_flutter

NFC in Flutter is a plugin for reading and writing NFC tags in Flutter. It works on both Android and iOS with a simple stream interface.

⚠️ Currently only NDEF formatted tags are supported.

Usage

Read NFC tags

// NFC.readNDEF returns a stream of NDEFMessage
Stream<NDEFMessage> stream = NFC.readNDEF();

stream.listen((NDEFMessage message) {
    print("records: ${message.records.length}");
});

Read one NFC tag

NDEFMessage message = await NFC.readNDEF(once: true).first;
print("payload: ${message.payload}");
// once: true` only scans one tag!

Writing to tags

You can access a message's NFC tag using the NDEFMessage's .tag property. The tag has a .write method, which allows you to write a NDEF message to the tag.

Note that the read stream must still be open when the .write method is called. This means that the once argument in .readNDEF() cannot be used.

Stream<NDEFMessage> stream = NFC.readNDEF();

stream.listen((NDEFMessage message) {
    NDEFMessage newMessage = NDEFMessage.withRecords(
        NDEFRecord.mime("text/plain", "hello world")
    );
    message.tag.write(newMessage);
});

You can also use the NFC.writeNDEF(NDEFMessage) method, which wraps the code above with support for the once argument.

NDEFMessage newMessage = NDEFMessage.withRecords(
    NDEFRecord.mime("text/plain", "hello world")
);
Stream<NDEFTag> stream = NFC.writeNDEF(newMessage);

stream.listen((NDEFTag tag) {
    print("wrote to tag");
});

If you only want to write to one tag, you can set the once argument to true.

NDEFMessage newMessage = NDEFMessage.withRecords(
    NDEFRecord.mime("text/plain", "hello world")
);
Stream<NDEFTag> stream = NFC.writeNDEF(newMessage, once: true);

stream.listen((NDEFTag tag) {
    print("only wrote to one tag!");
});

And if you would rather use a Future based API, you can await the returned stream's .first method.

NDEFMessage newMessage = NDEFMessage.withRecords(
    NDEFRecord.type("text/plain", "hello world")
);

await NFC.writeNDEF(newMessage, once: true).first;

Example

import 'package:nfc_in_flutter/nfc_in_flutter.dart';

class NFCReader extends StatefulWidget {
    @override
    _NFCReaderState createState() => _NFCReaderState();
}

class _NFCReaderState extends State {
    bool _supportsNFC = false;
    bool _reading = false;
    StreamSubscription<NDEFMessage> _stream;

    @override
    void initState() {
        super.initState();
        // Check if the device supports NFC reading
        NFC.isNDEFSupported
            .then((bool isSupported) {
                setState(() {
                    _supportsNFC = isSupported;
                });
            });
    }

    @override
    Widget build(BuildContext context) {
        if (!_supportsNFC) {
            return RaisedButton(
                child: const Text("You device does not support NFC"),
                onPressed: null,
            );
        }

        return RaisedButton(
            child: Text(_reading ? "Stop reading" : "Start reading"),
            onPressed: () {
                if (_reading) {
                    _stream?.cancel();
                    setState(() {
                        _reading = false;
                    });
                } else {
                    setState(() {
                        _reading = true;
                        // Start reading using NFC.readNDEF()
                        _stream = NFC.readNDEF(
                            once: true,
                            throwOnUserCancel: false,
                        ).listen((NDEFMessage message) {
                            print("read NDEF message: ${message.payload}"),
                        }, onError: (e) {
                            // Check error handling guide below
                        });
                    });
                }
            }
        );
    }
}

Full example in example directory

Installation

Add nfc_in_flutter to your pubspec.yaml

dependencies:
    nfc_in_flutter: 2.0.5

iOS

On iOS you must add turn on the Near Field Communication capability, add a NFC usage description and a NFC entitlement.

Turn on Near Field Communication Tag Reading

Open your iOS project in Xcode, find your project's target and navigate to Capabilities. Scroll down to 'Near Field Communication Tag Reading' and turn it on.

Turning on 'Near Field Communication Tag reading'

  • Adds the NFC tag-reading feature to the App ID.
  • Adds the Near Field Communication Tag Reader Session Formats Entitlement to the entitlements file.

from developer.apple.com: Building an NFC Tag-Reader app

'Turn on Near Field Communication Tag Reading' capability  turned on for a project in Xcode

NFC Usage Description

Open your ios/Runner/Info.plist file and add a new NFCReaderUsageDescription key. It's value should be a description of what you plan on using NFC for.

<key>NFCReaderUsageDescription</key>
<string>...</string>

Android

Add the following to your app's AndroidManifest.xml file:

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

If your app requires NFC, you can add the following to only allow it to be downloaded on devices that supports NFC:

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

"What is NDEF?"

If you're new to NFC you may come to expect a lot of readNFC() calls, but instead you see readNDEF() and NDEFMessage. NDEF is just a formatting standard the tags can be encoded in. There are other encodings than NDEF, but NDEF is the most common one. Currently NFC in Flutter only supports NDEF formatted tags.

Host Card Emulation

NFC in Flutter supports reading from emulated host cards*.

To read from emulated host cards, you need to do a few things.

  • Call readNDEF() with the readerMode argument set to an instance of NFCDispatchReaderMode.
  • Insert the following <intent-filter /> in your AndroidManifest.xml activity:
<intent-filter>
    <action android:name="android.nfc.action.NDEF_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
  • Not properly tested on iOS

⚠️ Multiple reader modes

If you start a readNDEF() stream with the reader mode set to an instance of NFCDispatchReaderMode, while another stream is active with the NFCNormalReaderMode, it will throw a NFCMultipleReaderModesException.

Platform differences

When you call readNDEF() on iOS, Core NFC (the iOS framework that allows NFC reading) opens a little window. On Android it just starts listening for NFC tag reads in the background.

image from developer.apple.com: Near Field Communication

⚠️ This will also freeze Flutter while open. Please send a Pull Request if you can fix this.

Error handling

Errors are no exception to NFC in Flutter (hah, get it). The stream returned by NFC.readNDEF() can send 7 different exceptions, and even worse: they are different for each platform!

See the full example in the example directory for an example on how to check for errors.

Exceptions for both platforms

NDEFReadingUnsupportedException

Thrown when a reading session is started, but not actually supported.

iOS

NFCUserCanceledSessionException

Thrown when the user clicks Cancel/Done core NFC popup. If you don't need to know if the user canceled the session you can start reading with the throwOnUserCancel argument set to false like so: readNDEF(throwOnUserCancel: false)

NFCSessionTimeoutException

Core NFC limits NFC reading sessions to 60 seconds. NFCSessionTimeoutException is thrown when the session has been active for 60 seconds.

NFCSessionTerminatedUnexpectedlyException

Thrown when the reading session terminates unexpectedly.

NFCSystemIsBusyException

Throw when the reading session fails because the system is too busy.

Android

NFCIOException

Thrown when a I/O exception occurs. Will for example happen if a tag is lost while being read or a tag could not be connected to.

NDEFBadFormatException

Thrown when the tag is expected to NDEF formatted, but it is incorrectly formatted.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].