Dart Requires Chilkat v11.7.0+
Dart
QR Code with Binary Data
See more QR Code Examples
Demonstrates a QR code that holds arbitrary bytes rather than text. The payload type is binary and the bytes are given as base64 in payload.base64. Any byte value may be used, including zero. Keep in mind that many phone camera apps expect text, so binary payloads are for readers that you control.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 bytes to encode. Here they come from hex, but they could be loaded from a file with LoadFile.
final bd = CkBinData();
try {
bd.appendEncoded('000102030405FF00FE4368696C6B6174', 'hex');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
final json = CkJsonObject();
json.updateString('payload.type', 'binary');
json.updateString('payload.base64', bd.getEncoded('base64'));
json.updateString('output.path', 'qa_output/qr_binary.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('bytes given: ${bd.numBytes}');
print('bytes encoded: ${jsonOut.intOf('symbols[0].payloadBytes')}');
print('mode: ${jsonOut.stringOf('symbols[0].selectedEncoding.mode')}');
print('QR version: ${jsonOut.intOf('symbols[0].selectedEncoding.version')}');
// The image written to qa_output/qr_binary.png:
//
// Sample output:
// bytes given: 16
// bytes encoded: 16
// mode: byte
// QR version: 2
}