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.
Platform | Supported NFC Tags |
---|---|
Android | NDEF: A, B, F, V, BARCODE |
iOS | NDEF: NFC TYPE 1, 2, 3, 4, 5 |
Add to pubspec.yaml:
dependencies:
flutter_nfc_reader:
git:
url: git://github.com/matteocrippa/flutter-nfc-reader.git
ref: master
and then run the shell
flutter packages get
last step import to the project:
import 'package:flutter_nfc_reader/flutter_nfc_reader.dart';
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 18 in minSdkVersion in the build.gradle (Module: app)
defaultConfig {
...
minSdkVersion 18
...
}
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!
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:
- id > id of the tag
- content > content of the tag
- error > if any error occurs
FlutterNfcReader.read().then((response) {
print(response.content);
});
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);
});
- status > status of ncf reading or writing stoped
FlutterNfcReader.stop().then((response) {
print(response.status.toString());
});
For better details look at the demo app.
For help getting started with Flutter, view our online documentation.
For help on editing plugin code, view the documentation.
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!!