andrey-ushakov / esc_pos_printer

ESC/POS (thermal, receipt) printing for Flutter & Dart
BSD 3-Clause "New" or "Revised" License
351 stars 300 forks source link

Cannot print Image - The getter 'width' was called on null #103

Open xSuperMu opened 3 years ago

xSuperMu commented 3 years ago

I'm using: printer: EPSON TM-m30 esc_pos_printer: ^4.0.3

I'm trying to print an image using the following code:

import 'package:image/image.dart' as im;

final ByteData data = await image.toByteData();
Uint8List preImage = data.buffer.asUint8List();
im.Image img = im.decodeImage(preImage);
printer.image(img);

and it causes this error:

 Unhandled Exception: NoSuchMethodError: The getter 'width' was called on null.

I've tried to do the following:

import 'package:image/image.dart' as im;

final ByteData data = await image.toByteData();
Uint8List preImage = data.buffer.asUint8List();
im.Image img = im.decodeImage(preImage);
im.Image thumbnail = im.copyResize(img, width: 80);
printer.image(thumbnail);

and still causes the same error.