Sample code for 30+ languages & platforms
Dart Requires Chilkat v11.7.0+

Generate a QR Code with the Barcode Method

See more QR Code Examples

Demonstrates the Barcode method, which is the general form of QrCode: the request names the symbology, and everything else is the same. QrCode is Barcode with the symbology already set to qr, and identical requests to the two methods give identical results. A program that will produce more than one kind of barcode can use Barcode for all of them.

Chilkat Dart Downloads

Dart
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.

  final json = CkJsonObject();
  json.updateString('symbology', 'qr');
  json.updateString('payload.text', 'https://www.chilkatsoft.com/');
  json.updateString('output.path', 'qa_output/qr_from_barcode.png');
  json.updateBool('output.overwrite', true);
  json.updateString('output.return', 'none');

  final fmt = CkFormats();
  final jsonOut = CkJsonObject();
  try {
    fmt.barcode('generate', json, jsonOut);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print('symbology: ${jsonOut.stringOf('symbols[0].symbology')}');
  print('QR version: ${jsonOut.intOf('symbols[0].selectedEncoding.version')}');
  print('image: ${jsonOut.intOf('outputs[0].width')} x ${jsonOut.intOf('outputs[0].height')} pixels');

  // The image written to qa_output/qr_from_barcode.png:

  // image

  // Barcode requires the symbology.  QrCode does not.
  final json2 = CkJsonObject();
  json2.updateString('payload.text', 'https://www.chilkatsoft.com/');
  try {
    fmt.barcode('generate', json2, jsonOut);
  } on ChilkatException {
    print('without a symbology: ${jsonOut.stringOf('errors[0].code')} at ${jsonOut.stringOf('errors[0].path')}');
  }

  // Sample output:

  // symbology: qr
  // QR version: 3
  // image: 148 x 148 pixels
  // without a symbology: missingOption at /symbology
}