How to Convert a QrImageView widget into image in flutter

449 views Asked by At

I cannot figure out on how to convert a generated qr code by the use of QrImageView into a image file type that can be saved in the database

This is my code for generating a qr code:

Widget buildGenerateQrCode(){
    String qrData = '$docu_title, $docu_type, $docu_sender, $docu_recipient, $_selectedFile';
    return QrImageView(
        data: qrData,
        version: QrVersions.auto,
        size: 200.0,
    );
  }
2

There are 2 answers

0
AgainPsychoX On

Use QrPainter class of the qr_flutter package.

    ByteData qrBytes = await QrPainter(
      data: "http://www.google.com",
      topLeftRadius: 10,
      bottomLeftRadius: 10,
      topRightRadius: 10,
      bottomRightRadius: 10,
      gapless: true,
      version: QrVersions.auto,
      color: Color.fromRGBO(0, 118, 191, 1),
      emptyColor: Colors.white,
    ).toImageData(878);

You can do something with the image data, send it to database or save on disk.

Source: https://github.com/theyakka/qr.flutter/issues/115

0
theshivamlko On

Convert any UI widget to Image without package Creating raw image from Widget or Canvas and then save it local storage as file using dart:io and https://pub.dev/packages/path_provider