4

Here I have to use pdfImageFromImageProvider function to stateless widget. So, Is it possible to resolve this issue using stateless widget?

Future<Widget> getWidgetAsync(double size) async {
PdfImage val = await pdfImageFromImageProvider(
  pdf: pdf.document,
  image: fw.AssetImage('assets/' + iconPath),
);

return Container(
  width: size,
  height: size,
  decoration: BoxDecoration(
    color: layoutbg,
    shape: BoxShape.circle,
  ),
  child: Image(val),
);

}

jazzbpn
  • 6,441
  • 16
  • 63
  • 99

1 Answers1

0

Your method must return Future<Widget>, as I'm understanding your question's title is your error, its mean that you returning a Widget not Future<Widget>. To do that, you should wrap your widget inside the Future like this:

Future<Widget> getWidgetAsync(double size) async {
PdfImage val = await pdfImageFromImageProvider(
  pdf: pdf.document,
  image: fw.AssetImage('assets/' + iconPath),
);

return Future.value(Container(
  width: size,
  height: size,
  decoration: BoxDecoration(
    color: layoutbg,
    shape: BoxShape.circle,
  ),
  child: Image(val),
));

Hope this will work.

Babken
  • 658
  • 1
  • 7
  • 17
  • What kind of error do you get? Can you put the all error information under your question? – Babken Jul 29 '19 at 10:20
  • It works in the normal case of stateless widget when using the future builder.But, In my case I am using: 'package:printing/printing.dart' and 'package:pdf/widgets.dart';. And using this packages it is not possible to use FutureBuilder. – jazzbpn Jul 29 '19 at 10:23