Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Flutter NFC reader plugin for iOS and Android

License

NotificationsYou must be signed in to change notification settings

dotintent/flutter-nfc-reader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

PlatformSupported NFC Tags
AndroidNDEF: A, B, F, V, BARCODE
iOSNDEF: NFC TYPE 1, 2, 3, 4, 5

Only Android supports nfc tag writing

Installation

Add to pubspec.yaml:

dependencies:flutter_nfc_reader:^0.2.0

or to get the experimental one:

dependencies:flutter_nfc_reader:git:url:git://github.com/matteocrippa/flutter-nfc-reader.gitref: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 yourAndroidManifest.xml on the top

<uses-permissionandroid:name="android.permission.NFC" /><uses-featureandroid:name="android.hardware.nfc"android:required="true" />

Assign 19 in minSdkVersion in thebuild.gradle (Module: app)

defaultConfig {...minSdkVersion 19...}

iOS Setup

Atm onlySwift 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 aNfcData model, this model contains:

FlutterNfcReader.read() andFlutterNfcReader.onTagDiscovered() have an optional parameter, only foriOS, calledinstruction.You can pass aString 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 emitsNfcData 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 castFlutterNfcReader.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 aNfcData 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 callFlutterNfcReader.checkNFCAvailability().The method returnsNFCAvailability.available when NFC is supported and enabled,NFCAvailability.disabled when NFC is disabled (Android only) andNFCAvailability.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 onlinedocumentation.

For help on editing plugin code, view thedocumentation.

Contributing

Please take a quick look at thecontribution 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 allcontributors!!

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

flutter/flutter#20685

About

Flutter NFC reader plugin for iOS and Android

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp