qr.flutter icon indicating copy to clipboard operation
qr.flutter copied to clipboard

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

Open itss-sid opened this issue 2 years ago • 12 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,)
      );

itss-sid avatar Jun 14 '22 11:06 itss-sid

Use AssetImage or NetworkImage.

noga-dev avatar Jul 04 '22 18:07 noga-dev

Use AssetImage or NetworkImage.

Already tried, they give the same error.

itss-sid avatar Jul 05 '22 04:07 itss-sid

Show your code when using my above suggestion.

noga-dev avatar Jul 05 '22 05:07 noga-dev

image

itss-sid avatar Jul 05 '22 05:07 itss-sid

image

itss-sid avatar Jul 05 '22 05:07 itss-sid

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

itss-sid avatar Jul 05 '22 05:07 itss-sid

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

noga-dev avatar Jul 05 '22 05:07 noga-dev

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

noga-dev avatar Jul 05 '22 06:07 noga-dev

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 ?

itss-sid avatar Jul 05 '22 07:07 itss-sid

@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

noga-dev avatar Jul 11 '22 08:07 noga-dev

@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,
       
      );
    });

aklehm avatar Mar 22 '23 12:03 aklehm