theyakka / qr.flutter

QR.Flutter is a Flutter library for simple and fast QR code rendering via a Widget or custom painter.

Home Page:https://pub.dev/packages/qr_flutter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The argument type 'Image' can't be assigned to the parameter type 'Image?'.

itss-sid opened this issue · comments

I am trying to export a QR code with an embedded image but I am not able to do that because it doesn't accept any type of image. I have tried literally every type of image possible still it just won't accept. What does it want?

Error:
image

My Code:

final painter = QrPainter.withQr(
        qr: qrCode!,
        color: const Color(0xFF000000),
        gapless: true,
        embeddedImageStyle: null,
        embeddedImage: Image(image: null,)
      );

Use AssetImage or NetworkImage.

Use AssetImage or NetworkImage.

Already tried, they give the same error.

Show your code when using my above suggestion.

I know I have to enter image URL in NetworkImage, I just did for testing and to show you.

Oh you're using QrPainter, not QrImageView. Is that intentional?

QrPainter expects a type of Image from dart:ui, not flutter/widgets.

Oh you're using QrPainter, not QrImageView. Is that intentional?

Yes, I need an Embedded image when exporting the QR Code.

QrPainter expects a type of Image from dart:ui, not flutter/widgets.

So, what should I do to give it an Embedded image when exporting the QR ?

@lukef Can you convert this issue to discussion?

So, what should I do to give it an image when exporting the QR ?

https://pub.dev/packages/flutter_svg_provider

@itss-sid I just had the same problem and found the solution in the example of this package.
Here is my code, to solve it:

import 'dart:ui' as ui;
import 'dart:async';

final completer = Completer<ui.Image>();
final byteData = await rootBundle.load('assets/images/icon.png');
ui.decodeImageFromList(byteData.buffer.asUint8List(), completer.complete);
completer.future.then((embeddedImage) {
      QrPainter.withQr(
        qr: qr,
        embeddedImage: embeddedImage,
       
      );
    });

@itss-sid I just had the same problem and found the solution in the example of this package. Here is my code, to solve it:

import 'dart:ui' as ui;
import 'dart:async';

final completer = Completer<ui.Image>();
final byteData = await rootBundle.load('assets/images/icon.png');
ui.decodeImageFromList(byteData.buffer.asUint8List(), completer.complete);
completer.future.then((embeddedImage) {
      QrPainter.withQr(
        qr: qr,
        embeddedImage: embeddedImage,
       
      );
    });

this should be done under the hood 😖