Print PDF from component template

I designed the layout of a receipt that receives data from a collection and saved it as a component. To bypass redesigning the layout all over again in a custom action using the pdf and printing libraries, I have this code (find below): When trying to save the code I get an error: "The return type 'ReceiptComponent2Widget' isn't a 'Widget', as required by the closure's context.". Not sure what I am missing.

// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/backend/schema/structs/index.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

// Import necessary packages and files
import '/components/receipt_component2/receipt_component2_widget.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
import 'package:printing/printing.dart';

// Custom function to print the receipt using FlutterFlow component
Future<void> printReceiptWithComponent() async {
  final pdf = pw.Document();

  pdf.addPage(
    pw.Page(
      build: (pw.Context context) {
        return ReceiptComponent2Widget();
      },
    ),
  );

  // Save and print the PDF
  final pdfBytes = await pdf.save();
  await Printing.layoutPdf(onLayout: (PdfPageFormat format) async => pdfBytes);
}

// and then add the boilerplate code using the green button on the right!
3
6 replies