selvam920 / drago_usb_printer

GNU General Public License v3.0
1 stars 6 forks source link

Print image from widget incorrect when set width #2

Open alohadance98 opened 3 months ago

alohadance98 commented 3 months ago

Hi, First of all thank you for provide a great package. There is an issue when i print an image capture from widget when set width to container DragoUsbPrinter only print a part of the image. Here is the example code:

DragoUsbPrinter dragoUsbPrinter = DragoUsbPrinter();
ScreenshotController controller = ScreenshotController();

List<Map<String, dynamic>> devices =
    await DragoUsbPrinter.getUSBDeviceList();

if (devices.isNotEmpty) {
  Map<String, dynamic> device = devices.last;
  int vendorId = int.parse(device['vendorId']);
  int productId = int.parse(device['productId']);
  bool? isConnected = await dragoUsbPrinter.connect(vendorId, productId);
  if (isConnected != null && isConnected) {
    Widget container = Container(
      decoration: BoxDecoration(border: Border.all(color: Colors.black)),
      height: 1000,
      width: 380,
      child: const Column(
        mainAxisAlignment: MainAxisAlignment.end,
        children: [
          Text(
            "TEST",
            style: TextStyle(color: Colors.black, fontSize: 20),
          ),
        ],
      ),
    );
    Uint8List buf = await controller.captureFromWidget(container);

    final img.Image image = img.decodeImage(buf)!;
    final profile = await CapabilityProfile.load();
    final generator = Generator(PaperSize.mm58, profile);

    List<int> data = [];
    data += generator.image(image);
    await dragoUsbPrinter.write(Uint8List.fromList(data));
    await dragoUsbPrinter.close();
  }
}

DragoUsbPrinter only prints part of the widget above but if i remove width of container it will prints the widget with full height

alohadance98 commented 3 months ago

Untitled this is the result when i set width and not set width for widget