printWidget static method

Future<bool> printWidget(
  1. Widget widget, {
  2. required double width,
  3. required double height,
})

Print a bitmap from a Flutter widget.

Renders a Flutter widget to an image and prints it.

  • widget: The widget to render and print
  • width: Width of the rendered widget
  • height: Height of the rendered widget

Returns true if printing was successful.

Implementation

static Future<bool> printWidget(
  Widget widget, {
  required double width,
  required double height,
}) async {
  try {
    // Render the widget to an image
    final imagePath = await ImageUtils.renderWidgetToImage(
      widget,
      width: width,
      height: height,
    );

    // Print the rendered image
    return await printImage(imagePath);
  } catch (e) {
    print('Error printing widget: $e');
    return false;
  }
}