PavelS0 / docx_template_dart

A Docx template engine
Apache License 2.0
40 stars 20 forks source link

docx.generate(c) provide Exception: Concurrent modification during iteration: Instance(length:8) of '_GrowableList'. #21

Closed boris-ilic closed 2 years ago

boris-ilic commented 2 years ago

final docx = await DocxTemplate.fromBytes(bytes);

List<RowContent> rows = [];

for (int i = 0; i < test.testQuestions.length; i++) {
  rows.add(RowContent()
    ..add(TextContent("key1", "${i + 1}"))
    ..add(TextContent("key2", test.testQuestions[i].text)));
  for (int j = 0; j < test.testQuestions[i].questionAnswers.length; j++) {
    if (test.testQuestions[i].questionAnswers[j].correct == true &&
        test.testQuestions[i].questionAnswers[j].checked == true) {
      // ako je user odgovorio tacno
      rows.add(RowContent()
        ..add(TextContent(
            "key2", setAnswerOrder(j) + test.testQuestions[i].questionAnswers[j].text))
        ..add(TextContent("key3", "x")));
    } else if (test.testQuestions[i].questionAnswers[j].correct == false &&
        test.testQuestions[i].questionAnswers[j].checked == true) {
      rows.add(RowContent()
        ..add(TextContent(
            "key2", setAnswerOrder(j) + test.testQuestions[i].questionAnswers[j].text))
        ..add(TextContent("key4", "x")));
    } else {
      rows.add(RowContent()
        ..add(TextContent(
            "key2", setAnswerOrder(j) + test.testQuestions[i].questionAnswers[j].text)));
    }
  }
}

Content c = Content();
c
  ..add(TextContent("training", training.name))
  ..add(TextContent("name", "${user.firstName} ${user.lastName}"))
  ..add(TextContent("username", user.userName))
  ..add(TextContent("workPosition", user.jobPosition))
  ..add(TextContent("department", user.departmentName))
  ..add(TableContent("table", rows));

**final d = await docx.generate(c);**      LINE WITH ERROR
var dir = await getExternalStorageDirectory();
print('PUTANJA: ${dir.path}');
PavelS0 commented 2 years ago

what version of the dart sdk and docx_template are you using?

boris-ilic commented 2 years ago

flutter : 1.22.5 dart : 2.10.4 docx_template: ^0.2.10

cant update package because of flutter version, if i want i need to migrate whole app

thanks for response

PavelS0 commented 2 years ago

I have updated the legacy version, fixed concurrent modification and other fixes. https://pub.dev/packages/docx_template/versions/0.2.11