Error on printing our Images on Receipt via POS system

Viewed 285

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'.

1 Answers

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;
  }
Related