Flutter NFC reader plugin for iOS and Android

Overview

Flutter NFC Reader & Writer

A new flutter plugin to help developers looking to use internal hardware inside iOS or Android devices for reading and writing 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.

Supported NFC Format

Platform Supported NFC Tags
Android NDEF: A, B, F, V, BARCODE
iOS NDEF: NFC TYPE 1, 2, 3, 4, 5

Only Android supports nfc tag writing

Installation

Add to pubspec.yaml:

dependencies:
  flutter_nfc_reader: ^0.1.0

or to get the experimental one:

dependencies:
  flutter_nfc_reader:
    git:
      url: git://github.com/matteocrippa/flutter-nfc-reader.git
      ref: develop

and then run the shell

flutter packages get

last step import to the project:

import 'package:flutter_nfc_reader/flutter_nfc_reader.dart';

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

Assign 19 in minSdkVersion in the build.gradle (Module: app)

defaultConfig {
...
minSdkVersion 19
...
}

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.

In your Podfile add this code in the top

platform :ios, '8.0'
use_frameworks!

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 NfcData model, this model contains:

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

  • id > id of the tag
  • content > content of the tag
  • error > if any error occurs
FlutterNfcReader.read().then((response) {
    print(response.content);
});

Stream NFC

this function will return a Stream that emits NfcData everytime a tag is recognized. On Ios you can use this too but IOS will always show a bottom sheet when it wants to scan a NFC Tag. Therefore you need to explicitly cast FlutterNfcReader.read() when you expect a second value. When subscribing to the stream the read function is called a first time for you. View the Example for a sample implementation.

FlutterNfcReader.onTagDiscovered().listen((onData) {
  print(onData.id);
  print(onData.content);
});

Write NFC (Only Android)

This function will return a promise when a write occurs, till that very moment the reading session is open. The promise will return a NfcData model, this model contains:

  • content > writed in the tag
FlutterNfcReader.write("path_prefix","tag content").then((response) {
print(response.content);
});

Read & Write NFC (Only Android)

You can read and then write in an nfc tag using the above functions as follows

FlutterNfcReader.read().then((readResponse) {
    FlutterNfcReader.write(" ",readResponse.content).then((writeResponse) {
        print('writed: ${writeResponse.content}');
    });
});

Stop NFC

  • status > status of ncf reading or writing stoped
FlutterNfcReader.stop().then((response) {
    print(response.status.toString());
});

For better details look at the demo app.

Check NFC Availability

In order to check whether the Device supports NFC or not you can call FlutterNfcReader.checkNFCAvailability(). The method returns NFCAvailability.available when NFC is supported and enabled, NFCAvailability.disabled when NFC is disabled (Android only) and NFCAvailability.not_supported when the user's hardware does not support NFC.

IOS Specifics

IOS behaves a bit different in terms of NFC Scanning and writing.

  • Ids of the tags aren't possible in the current implementation
  • each scan is visible for the user with a bottom sheet

Getting Started

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

For help on editing plugin code, view the documentation.

Contributing

Please take a quick look at the contribution guidelines first. If you see a package or project here that is no longer maintained or is not a good fit, please submit a pull request to improve this file. Thank you to all contributors!!

to develop on ios you need to activate the "legacy" build system because of this issue in flutter:

https://github.com/flutter/flutter/issues/20685

Comments
  • WIP: Feature/add streaming

    WIP: Feature/add streaming

    I had the Problem that with my NFC Tag i could only scan a Tag once and not more than that. So I implemented the Eventchannel methods that just emit the onTagDiscovered values to dart. Therefore a User can now listen to the stream and scan as much nfc tags as he wants. I updated the example implementation and also the README to state how it works.

    Open for discussion why i marked this PR first as WIP.

    opened by henrysachs 10
  • Update to Android v2 embedding

    Update to Android v2 embedding

    This PR upgrade to android v2 embedding you should probabbly provide documentation on v1 embedding no longer being supported

    Changes

    • Update example app - Target Android 11 - Bump gradle to 6.6.1 - Migrate to v2 embedding
    • Migrate plugin to android v2 - update kotlin to 1.4.30 - Update to latest android - Use new v2 embedding

    P.S.: Please add the hacktoberfest label to here I want this to count :D thx

    hacktoberfest-accepted 
    opened by DRSchlaubi 8
  • Uses UIThread on Android when using channel

    Uses UIThread on Android when using channel

    Looks like after flutter 1.6 you need to jump back to the UIThread before sending messages over a channel More info here: https://flutter.dev/docs/development/platform-integration/platform-channels#jumping-to-the-ui-thread-in-android

    Since I don't own any ios devices, I can't test if the changes made to flutter 1.6 broke this plugin for ios as well. But since there is a chapter for making the switch to the main thread on ios as well, I would assume so. More info here: https://flutter.dev/docs/development/platform-integration/platform-channels#jumping-to-the-main-thread-in-ios

    opened by GauteHaugen 4
  • fixed reading NDEF tags on Android

    fixed reading NDEF tags on Android

    The fix 45a3a2551c96dc42f29ecaf6b59a3d3111254fd4 for reading NDEF messages on Android did almost work, except that setting NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK will result in Ndef.get(tag) always returing null. Removing the flag solves the problem. :-)

    The supplied patches fix this problem and provide some code cleanup.

    I tested this version on a Google Pixel (1) and did not encounter any problems so far.

    opened by tauu 2
  • Fix null safety

    Fix null safety

    PR is suppose to fix an issue mentioned here https://github.com/matteocrippa/flutter-nfc-reader/issues/93

    The problem was that pre-release version of dart were used and new tools didn't recognised it as nullsafety-compatible

    opened by xPutnikx 1
  • Fix exception when checking NFCavailability on phones without NFC

    Fix exception when checking NFCavailability on phones without NFC

    Currently we always throw an exception when there is no NFCAdapter even when calling "NfcAvailability" which does not always need a nfc adapter, which doesn't allow apps to check whether the phone supports NFC or not

    opened by DRSchlaubi 1
  • Implement the instruction parameter for iOS again

    Implement the instruction parameter for iOS again

    Even if the native Swift code still contains code for receiving and alertMessage from Flutter there is no way of actually using it in the library's Dart code. I couldn't find any reason for removing this in the commit which removed it so I added it again

    opened by DRSchlaubi 1
  • Some changes in the plugin

    Some changes in the plugin

    The writing function was added and the reading function was modified in android, in ios it works the same as before but in both cases it already happens to me with a stream, now it is with a future in both cases.

    In the Readme.md the changes to the operation of the plugin and a couple of tips on how to configure the gradle and podfile files for the proper functioning of the plugin on their respective platforms (android and IOS) were added

    opened by semakers 1
  • changed CoreNFC to be a weak framework

    changed CoreNFC to be a weak framework

    Currently Apps using this Plugin will not run on iPads, as the CoreNFC framework is currently not available on any iPad. Changing the requirement of CoreNFC to weak framework enables this apps to run even if the framework is not available.

    opened by tauu 1
  • migration to androidx

    migration to androidx

    latest stable flutter 1.2.1 has a breaking change and forces applications to migrate from android.support to androidx packages. this pull request should do the trick

    more info here:

    1. https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility
    2. https://medium.com/@gabrc52/how-to-migrate-your-flutter-app-to-androidx-1202ad43c8c8
    opened by ethael 1
  • use stream to be able to read nfc details without interruptions

    use stream to be able to read nfc details without interruptions

    Hi! I found a problem in your library. This issue mentioned in #26 and #8
    When you call a startNFC method, you could read a NFC tag only once, because a Dart MethodChannel doesn't allow to return multiple results. Using EventChannel instead you will be able to read a values until you call stopNFC.

    opened by xPutnikx 1
Owner
Matteo Crippa
πŸ‘¨πŸ»β€πŸ’» Senior Software Engineer
Matteo Crippa
Flutter beacons plugin for Android and iOS.

Beacons Flutter plugin to work with beacons. Supports Android API 16+ and iOS 8+. Features: Automatic permission management Ranging Monitoring (includ

Loup 76 Jan 6, 2023
Ready for Building Production-Ready Healthcare/ Doctor Consult Android and iOS app UI using Flutter.

Production-Ready Doctor Consultant App - Flutter UI Watch it on YouTube Packages we are using: flutter_svg: link Complete Source code (Patreon) In thi

Abu Anwar 211 Jan 1, 2023
ESC/POS (thermal, receipt) printing for Flutter & Dart (Android/iOS)

esc_pos_bluetooth The library allows to print receipts using a Bluetooth printer. For WiFi/Ethernet printers, use esc_pos_printer library. TODO (PRs a

Andrey 175 Jan 6, 2023
This Android/IOS application intends to help users to get an early notification for slot availability for Covid19 vaccination.

Cowin Slot Reminder Objective: This Android/IOS application intends to help users to get an early notification for slot availability for Covid19 vacci

null 6 Oct 7, 2022
iOS App to Record Daily Sun Intake

Why Suncheck 당신은 ν•˜λ£¨μ— ν•΄λ₯Ό μ–Όλ§ˆλ‚˜ λ³΄λ‚˜μš”? μ½”μ‹œκ΅­μ— λ”μš± μš°μšΈν•˜κ±°λ‚˜ 무기λ ₯ν•œ 건 햇살을 μΆ©λΆ„νžˆ 받지 λͺ»ν•΄μ„œ 일 μˆ˜λ„ μžˆμ–΄μš”. 맀일 단 15λΆ„μ˜ ν–‡μ‚΄λ§ŒμœΌλ‘œ 우리 λ‡Œμ—μ„œλŠ” μš°μšΈμ¦μ„ μ˜ˆλ°©ν•  수 μžˆμ„ 만큼의 μ„Έλ‘œν† λ‹Œμ΄ λΆ„λΉ„λ©λ‹ˆλ‹€. λ§Œμ•½ ν•˜λ£¨ λ™μ•ˆ λ‚΄κ°€ μ–Όλ§ˆλ‚˜

Sohee Kim 14 Oct 18, 2022
Bluetooth plugin for Flutter

Introduction FlutterBlue is a bluetooth plugin for Flutter, a new app SDK to help developers build modern multi-platform apps. Alpha version This libr

Paul DeMarco 2.2k Jan 5, 2023
A Flutter plugin for turning your device into a beacon.

Beacon Broadcast plugin for Flutter A Flutter plugin for turning your device into a beacon. Usage To use this plugin, add beacon_broadcast as a depend

Paulina Szklarska 75 Dec 14, 2022
Using Bluetooth plugin in Flutter (flutter_bluetooth_serial)

Flutter Bluetooth NOTE: This is the updated version of the app (using flutter_bluetooth_serial 0.2.2). This version has much fewer bugs and provides a

Souvik Biswas 179 Nov 22, 2022
null 5 Nov 21, 2022
Vernet - Network Analyzer and Monitoring Tool

Vernet Vernet - Network Analyzer and Monitoring Tool Features Shows Wi-Fi details Scans for devices(or hosts) on network Scans for open ports of targe

null 109 Dec 28, 2022
I have created app to connect printer with bluetooth. And I already fix library bugs

flutter_bluetooth_printer A new Flutter application. Getting Started This project is a starting point for a Flutter application. A few resources to ge

Bounphone KOSADA 1 May 11, 2022
Source code and instructions for do-it-yourself projects.

Ammolytics Projects Source code and instructions for do-it-yourself projects. Projects Open Trickler is a Do-It-Yourself, mobile-controlled powder tri

Ammolytics 39 Nov 15, 2022
Flutter library that handles BLE operations for multiple devices.

Flutter reactive BLE library Flutter library that handles BLE operations for multiple devices. Usage The reactive BLE lib supports the following: BLE

Philips Hue 473 Jan 4, 2023
FlutterBleLib - A library for all your Bluetooth Low Energy needs in Flutter.

FlutterBleLib A library for all your Bluetooth Low Energy needs in Flutter. Internally utilises Polidea's MultiPlatformBleAdapter, which runs on RxAnd

null 4 Jun 10, 2022
Bluetooth Low Energy library for Flutter with support for simulating peripherals

FlutterBleLib A library for all your Bluetooth Low Energy needs in Flutter. Internally utilises Polidea's MultiPlatformBleAdapter, which runs on RxAnd

intent 509 Jan 3, 2023
A Flutter Template to communicate with an esp32 over bluetooth

Flutter Esp32 Bluetooth Template Changes in android/ [1 if you take the code to an other project, 2 still nessesarely]: Change minSdkVersion from 16 t

0x4d/Martin Loretz 23 Dec 20, 2022
This flutter app will help you to connect to Bluetooth Devices (like, HC-05)

Flutter Bluetooth NOTE: This is the updated version of the app (using flutter_bluetooth_serial 0.2.2). This version has much fewer bugs and provides a

Riyad Al-Ali 1 Jun 5, 2022
Flutter basic implementation for Classical Bluetooth (only RFCOMM for now)

flutter_bluetooth_serial Flutter basic implementation for Classical Bluetooth (only RFCOMM for now). Features The first goal of this project, started

null 1 Nov 7, 2022
Flutter plugin for accessing the NFC features on Android and iOS.

nfc_manager Flutter plugin for accessing the NFC features on Android and iOS. Note: This plugin depends on NFCTagReaderSession (requires iOS 13.0 or l

null 126 Jan 1, 2023
Iridium-reader-widget - Plug and play reader widget allowing to easily integrate an Iridium viewer inside any app

Plug and play reader widget allowing to easily integrate an Iridium viewer insid

Mantano 15 Dec 31, 2022