Dart Requires Chilkat v11.7.0+
Dart
Create a vCard (Contact) QR Code
See more QR Code Examples
Demonstrates a QR code that adds a contact to a phone when scanned. The text is a vCard, the standard format for contact details: lines between BEGIN:VCARD and END:VCARD, each ending with CRLF. A vCard is fairly long, so the symbol is larger than one holding a web address. Leave out the fields that are not needed to keep it small.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The second argument of AppendLine is cktrue to end each line with CRLF.
final sbCard = CkStringBuilder();
sbCard.appendLine('BEGIN:VCARD', true);
sbCard.appendLine('VERSION:3.0', true);
sbCard.appendLine('N:Smith;Alex;;;', true);
sbCard.appendLine('FN:Alex Smith', true);
sbCard.appendLine('ORG:Example Company', true);
sbCard.appendLine('TITLE:Sales Manager', true);
sbCard.appendLine('TEL;TYPE=CELL:+1-555-0100', true);
sbCard.appendLine('EMAIL:alex.smith@example.com', true);
sbCard.appendLine('URL:https://www.example.com', true);
sbCard.appendLine('END:VCARD', true);
final json = CkJsonObject();
json.updateSb('payload.text', sbCard);
json.updateInt('render.moduleSize', 6);
json.updateString('output.path', 'qa_output/qr_vcard.png');
json.updateBool('output.overwrite', true);
json.updateString('output.return', 'none');
final fmt = CkFormats();
final jsonOut = CkJsonObject();
try {
fmt.qrCode('generate', json, jsonOut);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print('vCard length: ${sbCard.length}');
print('QR version: ${jsonOut.intOf('symbols[0].selectedEncoding.version')}');
print('modules: ${jsonOut.intOf('symbols[0].dimensions.modulesWide')} x ${jsonOut.intOf('symbols[0].dimensions.modulesHigh')}');
print('image: ${jsonOut.intOf('outputs[0].width')} x ${jsonOut.intOf('outputs[0].height')} pixels');
// The image written to qa_output/qr_vcard.png:
//
// Sample output:
// vCard length: 197
// QR version: 10
// modules: 57 x 57
// image: 390 x 390 pixels
}