在fluter中用动态行破解一个pdf表格。

问题描述 投票:0回答:1

我想做动态表与列表内容无法映射数组列表与列表类型的表数据米没有得到表在PDF,而是显示我的错误。

这是我的pdf代码。

   goTocreatePdf(context,AllTranList) async {
   final Document pdf = Document();

    pdf.addPage(MultiPage(
    pageFormat:
    PdfPageFormat.letter.copyWith(marginBottom: 1.5 * PdfPageFormat.cm),
    crossAxisAlignment: CrossAxisAlignment.start,
    header: (Context context) {
    if (context.pageNumber == 1) {
      return null;
    }
    return Container(
        alignment: Alignment.centerRight,
        margin: const EdgeInsets.only(bottom: 3.0 * PdfPageFormat.mm),
        padding: const EdgeInsets.only(bottom: 3.0 * PdfPageFormat.mm),
        decoration: const BoxDecoration(
            border:
            BoxBorder(bottom: true, width: 0.5, color: PdfColors.grey)),
        child: Text('Report',
            style: Theme.of(context)
                .defaultTextStyle
                .copyWith(color: PdfColors.grey)));
  },
  footer: (Context context) {
    return Container(
        alignment: Alignment.centerRight,
        margin: const EdgeInsets.only(top: 1.0 * PdfPageFormat.cm),
        child: Text('Page ${context.pageNumber} of ${context.pagesCount}',
            style: Theme.of(context)
                .defaultTextStyle
                .copyWith(color: PdfColors.grey)));
  },
  build: (Context context) => <Widget>[
    Header(
        level: 0,
        child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Text('TRANSACTION LIST', textScaleFactor: 2),
              PdfLogo()
            ])),
    Header(level: 1, text: 'What is Lorem Ipsum?'),

            Table.fromTextArray(context: context, data:  <List<String>>[
        <String>[ 'TRANSACTION_AMOUNT No', 'CUSTREF_ID', 
  'REMARKS','PAYEE_VIR_ID','PAYER_VIR_ID'],
  ...AllTranList.map(
          (item) => [item.TRANSACTION_AMOUNT, 
       item.CUSTREF_ID,item.REMARKS,item.PAYEE_VIR_ID,item.PAYER_VIR_ID])
        ]),

       //save PDF
       final String dir = (await getApplicationDocumentsDirectory()).path;
       final String path = '$dir/report.pdf';
       Dio dio = new Dio();
       final File file = File(path);
       await file.writeAsBytes(pdf.save());
       material.Navigator.of(context).push(
       material.MaterialPageRoute(
       builder: (_) => PdfViewerPage(path: path),
     ),
    );
  }

而且无法将pdf也保存在外部存储。

这是我映射的AllTransitList 。

      [{TRANSACTION_AMOUNT: 1.00, CUSTREF_ID: 001819655570, CREATED_ON: 2020-01-18T19:55:40.412Z, REMARKS: SUCCESS, RESPONSE: SUCCESS, PAYEE_VIR_ID: navyabj@fbl, PAYER_VIR_ID: abinthomas0073@oksbi}, {TRANSACTION_AMOUNT: 1.00, CUSTREF_ID: 002218989414, CREATED_ON: 2020-01-22T18:12:13.500Z, REMARKS: SUCCESS, RESPONSE: SUCCESS, PAYEE_VIR_ID: navyabj@fbl, PAYER_VIR_ID: abinthomas0073@oksbi}, {TRANSACTION_AMOUNT: 30.00, CUSTREF_ID: 002218162602, CREATED_ON: 2020-01-22T18:13:12.835Z, REMARKS: SUCCESS, RESPONSE: SUCCESS, PAYEE_VIR_ID: navyabj@fbl, PAYER_VIR_ID: aju@federal}, {TRANSACTION_AMOUNT: 36.00, CUSTREF_ID: 002219179966, CREATED_ON: 2020-01-22T19:23:21.377Z, REMARKS: SUCCESS, RESPONSE: SUCCESS, PAYEE_VIR_ID: navyabj@fbl, PAYER_VIR_ID: aju@federal}]
flutter flutter-layout
1个回答
0
投票

看这个库。

你可以创建PDF与此库。

https:/pub.devpackagespdf

希望对你有用

© www.soinside.com 2019 - 2024. All rights reserved.