Eng. Aws
Eng. Aws

Reputation: 179

How Can I generate QR code and Show it on a PDF page in Flutter

I am Building a Flutter App, and one of the Functionalities includes the following:

1- Generating Qr codes - no problem here if I am showing it on the screen. 2- Generating PDF file, then saving it and sharing it using native device Sharing, No problem here until I tried to include the Qr code in the PDF page!

I have been stuck with this for two days and tried too many approaches to solve this, sadly with no luck.

please help and thank you all in advance.

Upvotes: 5

Views: 6797

Answers (3)

Rasel Khan
Rasel Khan

Reputation: 4239

using this package (pdf package) you can use like this -->

final pdf = pw.Document();    
pw.BarcodeWidget(
        data: "demo",
        barcode: pw.Barcode.qrCode(),
        width: 100,
        height: 50
    ),

result is:
enter image description here

Upvotes: 2

Ali Solanki YouTuber
Ali Solanki YouTuber

Reputation: 1468

You can use the Barcode widget from the pdf package. https://pub.dev/packages/pdf

import 'package:pdf/widgets.dart' as pw;

//Barcode widget inside pdf.addPage()
pw.BarcodeWidget(
  color: PdfColor.fromHex("#000000"),
  barcode: pw.Barcode.qrCode(),
  data: "My data",
),

Upvotes: 7

Eng. Aws
Eng. Aws

Reputation: 179

I have got the following answer from DavBfr / dart_pdf on GitHub and it worked:

Yes, there is a Widget for that:

BarcodeWidget( barcode: Barcode.qrCode(), data: 'here is a qrcode', )

You can use the same widget for Flutter too: https://pub.dev/packages/barcode_widget

Upvotes: 1

Related Questions