Flutter NFC Project - A new flutter plugin to help developers looking to use internal hardware inside iOS or Android devices for reading and writing NFC tags

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

You might also like...
Flutter plugin that leverages Storage Access Framework (SAF) API to get access and perform the operations on files and folders
Flutter plugin that leverages Storage Access Framework (SAF) API to get access and perform the operations on files and folders

Flutter plugin that leverages Storage Access Framework (SAF) API to get access and perform the operations on files and folders.

A flutter plugin to scan stripe readers and connect to the them and get the payment methods.

stripe_terminal A flutter plugin to scan stripe readers and connect to the them and get the payment methods. Installation Android No Configuration nee

Extension functions over Android's callback-based APIs which allows writing them in a sequential way within coroutines or observe multiple callbacks through kotlin flow.

callback-ktx A lightweight Android library that wraps Android's callback-based APIs into suspending extension functions which allow writing them in a

A framework for writing composable parsers based on Kotlin Coroutines.

Parsus A framework for writing composable parsers based on Kotlin Coroutines. val booleanGrammar = object : GrammarBooleanExpression() { val ws

A declarative, Kotlin-idiomatic API for writing dynamic command line applications.
A declarative, Kotlin-idiomatic API for writing dynamic command line applications.

A declarative, Kotlin-idiomatic API for writing dynamic command line applications.

1aingenieriaygas native base android - Project base for the migration of the Flutter App of 1A Ingenieria y Gas
1aingenieriaygas native base android - Project base for the migration of the Flutter App of 1A Ingenieria y Gas

1A Ingenieria y Gas App Versión Wordpress Backend Este proyecto se encuentra sol

A Gradle plugin for Kotlin Multiplatform projects that generate a XCFramework for Apple targets or a FatFramework for iOS targets, and manages the publishing process in a CocoaPod Repository.

KMP Framework Bundler KMP Framework Bundler is a Gradle plugin for Kotlin Multiplatform projects that generate a XCFramework for Apple targets or a Fa

Kotlin Multiplatform is an SDK for cross-platform mobile development, which enables teams to use the same business logic in both Android and iOS client applications.
Kotlin Multiplatform is an SDK for cross-platform mobile development, which enables teams to use the same business logic in both Android and iOS client applications.

Kotlin Multiplatform is an SDK for cross-platform mobile development, which enables teams to use the same business logic in both Android and iOS client applications.

An tool to help developer to use Retrofit elegantly while using kotlinx.coroutines.

one An tool to help developer to use Retrofit elegantly while using kotlinx.coroutines. Feature Transform different data structs to one. {errorCode, d

Owner
Muhammad Bilal
Hello i am Bilal idrees a Flutter developer and working in this field for the past 3 years. I have also been an Android Native Developer.
Muhammad Bilal
Muhammad Bilal 0 Jan 6, 2022
Esp touch flutter plugin - Client-side (mobile) Android Flutter implementation for ESP-Touch protocol

esp_touch_flutter_plugin Client-side (mobile) Android Flutter implementation for

huangyanxiong 0 Jan 21, 2022
Open as default - A flutter plugin that allows setting up your flutter app to open files as default

open_as_default A flutter plugin that allows setting up your flutter app to open

LuisDeLaValier 3 Nov 15, 2022
Small Kafka Playground to play around with Test Containers, and KotlinX Coroutines bindings while reading Kafka Definite Guide V2

KafkaPlayground Small playground where I'm playing around with Kafka in Kotlin and the Kafka SDK whilst reading the Kafka book Definite Guide from Con

Simon Vergauwen 34 Dec 30, 2022
Kotlin Multiplatform (KMP) library for reading resources in tests

kotlinx-resources Kotlin Multiplatform (KMP) plugin and library that add support for reading resources in tests. The plugin and a library work in tand

Gonçalo Silva 29 Dec 27, 2022
📌 replaces mutable tags or branch names by commit shas in your GitHub actions

?? pin-github-actions Using a branch name or tag name as a version for a GitHub action is dangerous as neither branches nor tags are immutable. (See G

Martin Bonnin 10 Jul 21, 2022
use kmm to write a flutter plugin

use KMM to write a flutter plugin The reference plugin_codelab example plugin that accompanies the How to write a Flutter plugin codelab. I changed pl

libill 8 Nov 9, 2022
With MaterialTimelineView you can easily create a material looking timeline.

MaterialTimelineView With MaterialTimelineView you can easily create a material looking timeline. Setup The library is pushed to jCenter() as an AAR,

Przemek 454 Dec 19, 2022
A Flutter implementation of Salesforce Marketing Cloud for iOS and Android

sfmc_flutter A Flutter implementation of Salesforce Marketing Cloud for iOS and Android. Features Setup Marketing Cloud (iOS and Android) Support for

Alex Tarragó 5 Oct 19, 2022