PavelS0 / docx_template_dart

A Docx template engine
Apache License 2.0
43 stars 31 forks source link

Fix for: Cannot modify an unmodifiable list (@GeraldGZ's solution in #53) #58

Open hunterwilhelm opened 2 months ago

hunterwilhelm commented 2 months ago

Copied from @GeraldGZ's solution

Solved: docx_entry.dart function _updateData in line 25 old:

void _updateData(Archive arch, List<int> data) {
    if (_index < 0) {
      arch.addFile(ArchiveFile(_name, data.length, data));
    } else {
      arch.files[_index] = ArchiveFile(_name, data.length, data);
    }
}

change to:

void _updateData(Archive arch, List<int> data) {
      arch.addFile(ArchiveFile(_name, data.length, data));
}

because lib "archive" is used and there is a change in archive.dart with new version:

class Archive extends IterableBase<ArchiveFile> {
List<ArchiveFile> get files => UnmodifiableListView(_files);    //  <-- problem

but the addFile has new behavior:

// Adding a file with the same path as one that's already in the archive
// will replace the previous file.
hunterwilhelm commented 2 months ago

53