flutter - 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,
),
),
];
}));
}
推荐阅读
- nginx - 如何在 nginx certbot 中将非 www 重定向到 www
- amazon-web-services - 在 EC2 中部署的 Tomcat Webapp 无法与 Postgres RDS 实例通信
- react-native - 我想知道让底部导航上方的输入组件反应原生博览会
- javascript - 关于 addEventListener 的 JSHint 警告“`在引用外部范围变量的循环中声明的函数可能会导致语义混淆”
- javafx - 当我将光标移动到 2D 东西上时,移动的 3D 对象将在 JavaFX 中冻结
- python - 在 MicroPython 中,如何从字符串中加载模块
- python - Peewee:不理解为什么代码生成“外键约束失败”的概念
- arrays - 当分配的数组值更改时,ruby 哈希数组值会更改
- python - 在 Jupyter Notebook 中加载 Keras 模型时出现 JSONDecodeError
- javascript - 显示:使用 js 阻止整个文档