printWidget static method
Print a bitmap from a Flutter widget.
Renders a Flutter widget to an image and prints it.
widget: The widget to render and printwidth: Width of the rendered widgetheight: 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;
}
}