Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve "The argument type 'ImageProvider<Object>' can't be assigned to the parameter type 'ImageProvider'?" in flutter

Tags:

flutter

I am using flutter printing library to make selected images as pdf. I have a list and inside that list there are paths of the selected images. Here is the code:

final doc = pw.Document();


    for(var i=0;i>selected.length;i++){
      Image img=Image.file(File(selected[i]));
      ImageProvider image=img.image;



      doc.addPage(pw.Page(
          build: (pw.Context context) {
            return pw.Center(
              child: pw.Image(image),
            ); // Center
          })); // Page




    }

pw.Image only accepts ImageProvider but i am getting this error:

The argument type 'ImageProvider<Object>' can't be assigned to the parameter type 'ImageProvider'.

How can i solve this problem?

like image 464
cvsrt Avatar asked Oct 22 '25 16:10

cvsrt


1 Answers

Call ImageProvider from "pw" like this...

doc.addPage(pw.Page(
          pageFormat: PdfPageFormat.a4,
          build: (pw.Context context) {
            return pw.Center(
              child: pw.Image(pw.MemoryImage(imageBytes)),
            ); // Center
          })); // Page
like image 142
Şan Sıtkı BAYRAMOĞLU Avatar answered Oct 24 '25 16:10

Şan Sıtkı BAYRAMOĞLU



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!