printImageWithCaption static method

Future<bool> printImageWithCaption(
  1. String imagePath, {
  2. required String caption,
  3. int width = 0,
  4. Alignment alignment = Alignment.center,
  5. double fontSize = 18,
})

Print an image with a caption.

Prints an image followed by a centered caption text.

  • imagePath: Path to the image file
  • caption: Text caption to print below the image
  • width: Width to resize the image (0 = printer default)
  • alignment: Image alignment (left, center, right)
  • fontSize: Font size for the caption text

Returns true if printing was successful.

Implementation

static Future<bool> printImageWithCaption(
  String imagePath, {
  required String caption,
  int width = 0,
  Alignment alignment = Alignment.center,
  double fontSize = 18,
}) async {
  try {
    // First print the image
    final imageResult = await printImage(
      imagePath,
      width: width,
      alignment: alignment,
    );

    if (!imageResult) {
      return false;
    }

    // Then print the caption
    final captionResult = await PrinterText.printCenteredText(
      text: caption,
      fontSize: fontSize,
    );

    return captionResult;
  } catch (e) {
    print('Error printing image with caption: $e');
    return false;
  }
}