(...)
DocxTemplate? template;
(...)
final data = await rootBundle.load(file.path);
final bytes = data.buffer.asUint8List();
template = await DocxTemplate.fromBytes(bytes);
Step 2: Once the template is loaded, I get its tags to show to the user:
final formFields = widget.docController.template.getTags()
Step 3: After getting values of the tags, I try to use the same reference of template and save it:
final docGenerated = await widget.docController.template.generate(content);
final of = File(filePath);
await of.writeAsBytes(docGenerated);
The problem is that the doc file is corrupted. But, if I load the DocxTemplate instance once again using fromBytes, the document is generated correctly. Alternatively, I did another test: I commented out the line that getTags() and generated the docx without reloading the DocxTemplate instance once again using fromBytes, and it worked as expected. In other words, as the title of this issue says: when I call getTags and later try to use the template reference, it generates a corrupted docx file.
@PavelS0
Consider the following scenario:
Step 1: I load a docx file:
Step 2: Once the template is loaded, I get its tags to show to the user:
Step 3: After getting values of the tags, I try to use the same reference of template and save it:
The problem is that the doc file is corrupted. But, if I load the DocxTemplate instance once again using fromBytes, the document is generated correctly. Alternatively, I did another test: I commented out the line that getTags() and generated the docx without reloading the DocxTemplate instance once again using fromBytes, and it worked as expected. In other words, as the title of this issue says: when I call getTags and later try to use the template reference, it generates a corrupted docx file.
Any suggestion?
Thank you!