Add VCardRecord for NFC vCard contact sharing#33
Merged
Harry-Chen merged 2 commits intonfcim:masterfrom Mar 14, 2026
Merged
Conversation
Contributor
|
@klaasdannen Thanks again! Could you rebase against the latest master branch, and put your test file into |
There was a problem hiding this comment.
Pull request overview
Adds first-class vCard (“text/vcard”) support to the NDEF library so applications can encode/decode contact cards via NFC as a dedicated VCardRecord instead of treating them as generic MimeRecords.
Changes:
- Introduces
VCardRecordplus supportingVCardName,VCardPhone, andVCardAddressmodels with vCard build/parse logic. - Registers
VCardRecordinNDEFRecord.defaultTypeFactoryand exports it from the publicndef.dartbarrel. - Adds a comprehensive
vcard_test.dartsuite covering encoding/decoding, v2.1 type parameters, unfolding, and multi-record messages.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
lib/records/media/vcard.dart |
New vCard record implementation (encode/decode + helpers + models). |
lib/record.dart |
Registers VCardRecord for media TNF type dispatch. |
lib/ndef.dart |
Exports the new vCard record API. |
test/vcard_test.dart |
Adds vCard-focused unit tests and round-trip coverage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+299
to
+307
| /// Escapes a single N-property component (`;` and `\` must be escaped). | ||
| static String _escapeComponent(String value) { | ||
| return value.replaceAll(r'\', r'\\').replaceAll(';', r'\;'); | ||
| } | ||
|
|
||
| /// Unescapes a single N-property component. | ||
| static String _unescapeComponent(String value) { | ||
| return value.replaceAll(r'\;', ';').replaceAll(r'\\', r'\'); | ||
| } |
Comment on lines
+401
to
+423
| /// Encodes the address to vCard ADR property line. | ||
| String encode() { | ||
| final value = '$poBox;$extended;$street;$city;$region;$postalCode;$country'; | ||
| if (type != null) { | ||
| return 'ADR;TYPE=$type:$value'; | ||
| } | ||
| return 'ADR:$value'; | ||
| } | ||
|
|
||
| /// Decodes a vCard ADR property value string. | ||
| static VCardAddress decode(String value, String parameters) { | ||
| final parts = value.split(';'); | ||
| final type = _extractTypeParam(parameters); | ||
| return VCardAddress( | ||
| type: type, | ||
| poBox: parts.isNotEmpty ? parts[0] : '', | ||
| extended: parts.length > 1 ? parts[1] : '', | ||
| street: parts.length > 2 ? parts[2] : '', | ||
| city: parts.length > 3 ? parts[3] : '', | ||
| region: parts.length > 4 ? parts[4] : '', | ||
| postalCode: parts.length > 5 ? parts[5] : '', | ||
| country: parts.length > 6 ? parts[6] : '', | ||
| ); |
Comment on lines
+209
to
+210
| line = line.trim(); | ||
| if (line.isEmpty) continue; |
Comment on lines
+17
to
+21
| return value | ||
| .replaceAll(r'\n', '\n') | ||
| .replaceAll(r'\,', ',') | ||
| .replaceAll(r'\;', ';') | ||
| .replaceAll(r'\\', r'\'); |
Comment on lines
+304
to
+307
| /// Unescapes a single N-property component. | ||
| static String _unescapeComponent(String value) { | ||
| return value.replaceAll(r'\;', ';').replaceAll(r'\\', r'\'); | ||
| } |
Comment on lines
+8
to
+12
| return value | ||
| .replaceAll(r'\', r'\\') | ||
| .replaceAll(',', r'\,') | ||
| .replaceAll(';', r'\;') | ||
| .replaceAll('\n', r'\n'); |
Comment on lines
+18
to
+22
| .replaceAll(r'\n', '\n') | ||
| .replaceAll(r'\,', ',') | ||
| .replaceAll(r'\;', ';') | ||
| .replaceAll(r'\\', r'\'); | ||
| } |
Implements RFC 6350 vCard encoding/decoding as an NDEF media record. Supports vCard 2.1, 3.0 and 4.0 formats with structured name, email, phone, address, organization and other standard properties. Includes proper escaping for N-property components and vCard 2.1 bare type parameter parsing.
bd9534d to
9425947
Compare
Harry-Chen
approved these changes
Mar 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
VCardRecordextendingMimeRecordfor encoding/decoding vCard contacts via NFC (MIME typetext/vcard)TEL;CELL:vsTEL;TYPE=CELL:), line unfolding (RFC 6350), and proper escaping of special characters in N-property componentsChanges
lib/records/media/vcard.dart-- newVCardRecord,VCardName,VCardPhone,VCardAddressclasseslib/ndef.dart-- export vcard.dartlib/record.dart-- registerVCardRecordindefaultTypeFactorytest/vcard_test.dart-- 17 tests covering construction, round-trip encoding, real-world payloads, v2.1 parsing, special characters, line unfolding, and multi-record NDEF messagesTest plan
dart test test/vcard_test.dart)dart formatproduces no changes