2

Here is my code below.

 Future<List<int>> getImage() async {
    List<int> bytes = [];
    CapabilityProfile profile = await CapabilityProfile.load();
    final generator = Generator(PaperSize.mm80, profile);

    final ByteData data = await rootBundle.load('assets/logo.png');
    final buffer = data.buffer;
    final image = base64.encode(Uint8List.view(buffer));
    bytes += generator.image(image);

    return bytes;
  }

At

bytes += generator.image(image); 

the error said that

Error: The argument type 'String' can't be assigned to the parameter type 'Image'.

James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

0

from The docs

you need to pass the bytes not the base64

it looks like you miss decodeImage()

Future<List<int>> getImage() async {
    List<int> bytes = [];
    CapabilityProfile profile = await CapabilityProfile.load();
    final generator = Generator(PaperSize.mm80, profile);

    final ByteData data = await rootBundle.load('assets/logo.png');
    final Uint8List buffer = data.buffer.asUint8List();
    final Image image = decodeImage(buffer);

    bytes += generator.image(image);

    return bytes;
  }
flaxon
  • 928
  • 4
  • 18