1

before i start add my question I tried to solve my problem with posts put here but no one of solution solved my problem ,like this post : Flutter -PDF -- Error -

I am trying to create pdf file using dynamic data from api as nested list, I tried listview.builder then for loop with column and wrap widgets but the problem is still as it.

I tried this :

import 'dart:io';
import 'package:open_file/open_file.dart';
import 'package:path_provider/path_provider.dart';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart';

class PdfCreatorApi {
  static Future<File> roundRobinMethod(list, name) async {
    final pdf = Document();
    pdf.addPage(MultiPage(
        margin: EdgeInsets.all(50),
        pageFormat: PdfPageFormat.a4,
        build: (Context context) => [
              Wrap(children: [buildRoundRobinMethod(list, name)]),
            ]));
    return savePdf(name: '$name.pdf', pdf: pdf);
  }

then :

static Widget buildRoundRobinMethod(list, name) {
    return Column(children: [
      Padding(
          padding: EdgeInsets.only(bottom: 25),
          child: Center(
              child: Text("$name ",
                  style: TextStyle(
                      color: PdfColor.fromInt(0xff1e88e5), fontSize: 22)))),
      Column(children: [
        for (var i = 0; i < list.length; i++)
          Column(mainAxisAlignment: MainAxisAlignment.center, children: [
            Container(
                width: PdfPageFormat.a4.width,
                padding: EdgeInsets.all(10),
                color: PdfColor.fromInt(0xfF6F8FA),
                child: Paragraph(
                    text: 'Round ${list[i]['round']}',
                    textAlign: TextAlign.center,
                    style: TextStyle(
                      fontSize: 18,
                    ))),
            Padding(
                padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
                child: Column(children: [
                  for (var j = 0; j < list[i]['games'].length; j++)
                    Row(
                        mainAxisAlignment: MainAxisAlignment.spaceAround,
                        children: [
                          Paragraph(
                              text: '${list[i]['games'][j]['home']}',
                              textAlign: TextAlign.center,
                              style: TextStyle(
                                fontSize: 18,
                              )),
                          Text('  Vs  '),
                          Paragraph(
                              text: '${list[i]['games'][j]['home']}',
                              textAlign: TextAlign.center,
                              style: TextStyle(
                                fontSize: 18,
                              ))
                        ])
                ]))
          ])
      ])
    ]);
  }

I tried change columns with wrap and remove wrap widget from here :

build: (Context context) => [
                  Wrap(children: [buildRoundRobinMethod(list, name)]),
                ]));

but nothing change, just when I changed the page format to A3 then worked, but if I have longer loop sure will get same error.

How can I solve this?

Sermed mayi
  • 697
  • 7
  • 26

0 Answers0