I am trying to create a custom action that takes certain fields from a collection and puts them into a .pdf when a button is pressed. So far, with the help of this video, I've been able to get the action to work with text fields from my document, but I cannot figure out how to get the image from the document. Here's what I've tried:
// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/backend/schema/structs/index.dart';
import '/backend/schema/enums/enums.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 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
import 'package:printing/printing.dart';
Future oneRecord(ArtworksRecord myArg) async {
// Add your function code here!
final pdf = pw.Document();
final image = pw.MemoryImage(
File('myArg.artworkImage').readAsBytesSync(),
);
pdf.addPage(pw.Page(
build: (pw.Context context) => pw.Column(
children: [
pw.Text('Title : ' + myArg.artworkTitle),
pw.Text('Medium : ' + myArg.artworkMedium),
pw.Image(image),
],
)));
await Printing.layoutPdf(
onLayout: (PdfPageFormat format) async => pdf.save());
}
But it returns an error with this section:
final image = pw.MemoryImage(
File('myArg.artworkImage').readAsBytesSync(),
);
And the error says:
The function 'File' isn't defined. Try importing the library that defines 'File', correcting the name to the name of an existing function, or defining a function named 'File'.
How do I grab the image that is saved with the document record and put it into my .pdf? Maybe there's a package I should install? I have spent a lot of time banging my head against the wall on this. I would be very appreciative of any help or pointers!