【发布时间】:2021-02-01 04:38:34
【问题描述】:
我正在尝试在表格的最后一列中添加一个图标,以便它出现在 Pdf UI 中。我使用的依赖是 pdf: ^2.0.0, flutter_full_pdf_viewer: ^1.0.6, printing: ^4.0.0 但我得到一个错误说明作为Unhandled Exception: type 'IconData' is not a subtype of type 'String'。我可以知道我在做什么错误,因为我没有将图标声明为字符串,所以我可以知道这里有什么问题吗?
class Product {
const Product(this.serial,
this.articleNumber,
this.addresseeName,
this.remark,
this.image
);
final String serial;
final String articleNumber;
final String addresseeName;
final String remark;
final IconData image;
getIndex(int index) {
switch (index) {
case 0:
return serial;
case 1:
return articleNumber;
case 2:
return addresseeName;
case 3:
return remark.toString();
case 4:
return image;
}
return '';
}
}
final products = <Product>[
Product('1', 'RK1234567890IN', '', 'NOT DELIVERED', Icons.ac_unit),
Product('2', 'RM0987654321IN', 'Ramesh', 'DELIVERED \n ( To : name)\n29-01-2021 10:03:43', Icons.ac_unit),
Product('3', 'RL4345424741IN', 'Suresh', 'DELIVERED \n ( To : name)\n29-01-2021 10:30:13', Icons.ac_unit),
Product('4', 'RO9638642753IN', '', 'NOT DELIVERED', Icons.ac_unit),
];
这就是我声明表格的方式
pw.Widget _contentArticleTable(pw.Context context) {
const tableHeaders = [
'SERIAL',
'ARTICLE NUMBER',
'ADDRESSEE NAME',
'REMARK',
'SIGNATURE'
];
return pw.Table.fromTextArray(
cellAlignment: pw.Alignment.centerLeft,
headerDecoration: pw.BoxDecoration(
borderRadius: const pw.BorderRadius.all(pw.Radius.circular(2)),
color: PdfColors.grey200,
),
headerHeight: 25,
cellHeight: 40,
cellAlignments: {
0: pw.Alignment.center,
1: pw.Alignment.center,
2: pw.Alignment.center,
3: pw.Alignment.center,
4: pw.Alignment.center,
},
headerStyle: pw.TextStyle(
color: PdfColors.blueGrey,
fontSize: 10,
fontWeight: pw.FontWeight.bold,
),
cellStyle: const pw.TextStyle(
color: PdfColors.black,
fontSize: 10,
),
rowDecoration: pw.BoxDecoration(
border: pw.Border(
bottom: pw.BorderSide(
color: PdfColors.amber,
width: .5,
),
),
),
headers: List<String>.generate(
tableHeaders.length,
(col) => tableHeaders[col],
),
data: List<List<String>>.generate(
products.length,
(row) => List<String>.generate(
tableHeaders.length,
(col) => products[row].getIndex(col),
),
),
);
}
【问题讨论】:
-
你用什么小部件来显示图像?