For nested list my app crashes while generating pdf in flutter

Viewed 30

I am using pdf package for creating a PDF file in my app. I am trying to show transaction list of a month based on day. I was able to create pages for the first list using Wrap() widget. But for the inner transaction list it shows me error for more then 8 element. It doesn't break page automatically for list overflow.

So is there any solution for this problem?

Here is my code

class PdfParagraphApi {
static Future<File> generate(title) async {
final pdf = Document();

final customFont = Font.ttf(await rootBundle.load('assets/OpenSans-Regular.ttf'));

pdf.addPage(
  MultiPage(
    build: (context) => <Widget>[
      Wrap(
        children: List<Widget>.generate(7, (index) {
          return Container(
            margin: EdgeInsets.only(top: 3),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Header(child: Text(
                  "08 Sep, 2021",
                  style: TextStyle(
                    color: PdfColors.purple300,
                    fontWeight: FontWeight.bold,
                    fontSize: 17
                  )
                  )),
                  ///////////////////////// error starts here ////////////////
                Container(
              child: Wrap(
                children: List<Widget>.generate(9, (ind) {
                return cards();
                }))
                 ////////////////////////////////////////////////////////
               )
              ]
            )
          );
        })
      )
    ],
  
  ),
);
return PdfApi.saveDocument(name: 'my_example.pdf', pdf: pdf);
}


static Widget cards() => Container(
    decoration: BoxDecoration(
      color: PdfColors.grey300,
      borderRadius: BorderRadius.circular(5)
    ),
    margin: EdgeInsets.only(bottom: 8),
    child: Container(
      // width: 300,
      margin: EdgeInsets.all(8.0),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Flexible(
            child: Container(
              margin: EdgeInsets.only(left: 10),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Container(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          child: Text(
                            "VISA",
                            style: TextStyle(
                              fontSize: 16
                            )
                          ),
                        ),
                        SizedBox(height: 5),
                        Container(
                          child: Text(
                            "Token: 435645tRER3  Time: 12:45",
                          ),
                        ),
                      ],
                    ),
                  ),
                  Container(
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      crossAxisAlignment: CrossAxisAlignment.end,
                      children: [
                        Row(
                          children: [
                            Text(
                              "GBP 56.07",
                              maxLines: 1,
                              style: TextStyle(
                                fontWeight: FontWeight.bold
                              )
                            ),
                            Text(
                              // " - ${charge.refundDetails.refundedAmount}",
                              " - 45.87",
                              style: TextStyle(
                                fontSize: 12,
                                color: PdfColors.red,
                              ),
                            )
                          ],
                        ),
                        SizedBox(height: 5),
                  
                        Text(
                          "refunded",
                          style: TextStyle(
                              color: PdfColors.green),
                        ),
                        SizedBox(height: 5),
                        Text(
                           "Captured",
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    ),
  );

}

0 Answers
Related