While debugging this code snippet, I see that the the build callback is executed after the return, hence leaving the late w not assigned.
How can I do to schedule the call properly?
import 'package:pdf/widgets.dart' as pw;
class PdfPageIdentification {
PackageInfo packageInfo;
String smartboxId;
String smartboxMacAddress;
pw.Widget? label;
pw.Page? page;
PdfPageIdentification(
{required this.packageInfo,
required this.smartboxId,
required this.smartboxMacAddress,
this.label,
this.page});
}
/// Creates the battery identification label as a PDF file
static Future<PdfPageIdentification> identificationSheetPage(
PeripheralManufacturerData data) async {
final packageInfo = await PackageInfo.fromPlatform();
late PdfPageIdentification w;
final page = pw.Page(
pageFormat: PdfPageFormat.a4,
margin: pw.EdgeInsets.symmetric(horizontal: 180),
// margin: pw.EdgeInsets.all(40),
build: (pw.Context context) {
w = identificationSheet(data, packageInfo, context);
return w.label!;
});
w.page = page;
return w;
}