Flutter在初始化期间读取静态变量



我有一个布尔值要从另一个屏幕中的复选框传递,它是SubmitForm((类的valueToSend。我如何访问该变量,使错误消失,并且可以用作部分中的参数。错误是在初始化期间读取静态变量

var value = SubmitForm().valueToSend; //here is the error come 
final header = ['Parts', 'Check'];
final parts = [
Part(parts: 'Conveyor Belt', check: value ? 'done' : 'have issue'),];


class SubmitForm extends StatelessWidget {      
final bool valueToSend;
final data = parts.map((Part) => [Part.parts, Part.check]).toList();
}

我终于拿到了。

class SubmitForm extends StatelessWidget {

final String text;
final String taskName;
final currentDate;
final dropdownValue;
final bool valueToSend;
final pdf = pw.Document();
writeOnPdf() {
final parts = [
Part(parts: 'Conveyor Belt', check: valueToSend ? 'done' : 'have issue'), //i got it now
//      Part(parts: 'Gear Motor', check: 'done'),
//      Part(parts: 'Pulley&Roller', check: 'done'),
//      Part(parts: 'Side Frame', check: 'done'),
//      Part(parts: 'Motor', check: 'done'),
//      Part(parts: 'DMS', check: 'done'),
//      Part(parts: 'Sensor', check: 'done'),
//      Part(parts: 'Beacon', check: 'done'),
//      Part(parts: 'E/stop', check: 'done'),
];
final data = parts.map((Part) => [Part.parts, Part.check]).toList();
pdf.addPage(pw.MultiPage(
pageFormat: PdfPageFormat.a5,
margin: pw.EdgeInsets.all(32),
build: (pw.Context context) {
return <pw.Widget>[
pw.Header(level: 0, child: pw.Text('Date:$currentDate')),
pw.Header(
// show image from the asset image TODO provide image to pdf
level: 1,
child: pw.Text('Baggage Handling System T2, MA(SEPANG) SDN BHD',
style: pw.TextStyle(fontWeight: pw.FontWeight.bold))),
pw.Header(level: 2, child: pw.Text('PPM Inspection Check Sheet')),
pw.Paragraph(
text: '$taskName Subsystem $text done by shift $dropdownValue'),
pw.Table.fromTextArray(
headers: header,
data: data,
headerDecoration: pw.BoxDecoration(
color: PdfColors.grey300,
),
),
];
}));
}

最新更新