Search packages, repositories and app categories

Package detailsv0.4.0

ndef

A Dart library to decode & encode NDEF records, supporting multiple types.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
96.9K
Likes
17
Pub points
160

Install package

flutter pub add ndef

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The ndef package is a Dart library designed to decode and encode NDEF (NFC Data Exchange Format) records, enabling seamless interaction with NFC tags across multiple platforms. It supports various NDEF record types, making it ideal for applications involving contactless data exchange. Built with security in mind, it aligns well with cryptographic and permission-based workflows. The library is compatible with Android, iOS, Web, macOS, Windows, and Linux, offering broad cross-platform functionality for NFC-enabled apps.

Use cases

  • Reading and writing NFC tags
  • Building contactless payment systems
  • Enabling smart poster interactions
  • Creating secure device pairing flows
  • Developing IoT device configuration tools

Key features

  • Supports multiple NDEF record types
  • Cross-platform NFC compatibility
  • Secure data encoding and decoding
  • Lightweight and easy to integrate
  • Built-in validation for NDEF structures

Suitable for

  • Mobile app developers working with NFC
  • Security-focused application builders
  • IoT and smart device integrators
  • Web and desktop apps requiring NFC support

Considerations

  • Requires device-level NFC hardware
  • Platform-specific permissions must be handled
  • Limited to NDEF format only
  • No built-in encryption (external handling needed)
  • May require additional platform setup for full functionality

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

ndef

pub version Test

ndef is a Dart library to decode & encode NDEF records, supporting multiple types including (grouped by Type Name Format):

  • NFC Well-known Records (TNF 1 / urn:nfc:wkt:), with:
    • Text (class T)
    • URI with well-known prefix (class U)
    • Digital signature (class Sig)
    • Smart poster (class Sp), including sub-record:
      • Action (class act)
      • Size (class s)
      • Type (class t)
    • Connection handover (class Hr/Hs/Hm/Hi/Hc/ac/cr)
  • Media Records (TNF 2, containing MIME data), with:
    • Bluetooth easy pairing (class application/vnd.bluetooth.ep.oob)
    • Bluetooth low energy (class application/vnd.bluetooth.le.oob)
  • Absolute URI Records (TNF 3)
  • External Records (TNF 4 / urn:nfc:ext:), with:
    • Android application record (class android.com:pkg)

This library is still under active development and subject to breaking API changes and malfunction. Pull requests and issues are most welcomed, especially on:

  • Bug fixes
  • New support for other record types

Usage

import 'package:ndef/ndef.dart' as ndef;

// encoding
var uriRecord = new ndef.UriRecord.fromString("https://github.com/nfcim/ndef");
var textRecord = new ndef.TextRecord(text: "Hello");
var encodedUriRecord = uriRecord.encode().toHexString(); /// encode a single record, and use our extension method on [Uint8List]
var encodedAllRecords = ndef.encodeNdefMessage([uriRecord, textRecord]).toHexString(); // encode several records as a message

// decoding
var encodedTextRecord = "d1010f5402656e48656c6c6f20576f726c6421";
var decodedRecords = ndef.decodeRawNdefMessage(encodedTextRecord.toBytes());
assert(decodedRecords.length == 1);
if (decodedRecords[0] is ndef.TextRecord) {
  assert(decodeRecords[0].text == "Hello");
}  else {
  // we will not reach here
}

// data-binding (by implementing payload as dynamic getter / setter)
var origPayload = uriRecord.payload!;
print(origPayload.toHexString());
uriRecord.content = "github.com/nfcim/flutter_nfc_kit";
print(uriRecord.payload!.toHexString()); // changed
uriRecord.payload = origPayload;
print(uriRecord.content); // changed back

// decoding by providing parts of a record
var partiallyDecodedUrlRecord = ndef.decodePartialNdefMessage(ndef.TypeNameFormat.nfcWellKnown, utf8.encode("U"), origPayload, id: Uint8List.fromList([0x1, 0x2]));

See example code for a more complete example.

Refer to the documentation for detailed usage.

Categories

Dependencies

Dependency list 1 items

Source repository

Projects using this package