-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unsupported operation: Cannot modify an unmodifiable list exception #53
Comments
I struggled with the source code of the package. Imported it and then change
Then I found several |
I found out a workarround by overriding the dependency:
Then, it still doesn't work. The file is corrupted and can;t be openend: #37 (comment) But when trying out the full example like https://github.com/Fiat2U/docx_template_flutter_sample to see a working sample. It did work. It seems that the file gets corrupted if not all tags are filled. |
I tried and encountered |
I am encountering this issue as well. I've tried different versions of both the docx_template and archive packages, but always the same issue. Has anyone managed to make it work? |
I created another test. Since I noticed that if you won't fill all tags in your word document, the file get corrupted. I also noticed that if something is wrong with a tag in your template the file also get corrupted. So, to generated the documented I needed with my own template, I added tags step by step (tag by tag), till all tags were added and the template was complete. Please find my working test:
with test_resources/template.docx and test_resources/test.png pubspec.lock
generated from
Keep in mind that the deendency override is just a workarround, not a fix. |
In my case, following this #37 (comment) but putting the
and Working with My problem wasn't in a unit test, but I was using the normal way of doing things with this package (at least i think 😅) Some samples :
The "Unsupported operation: Cannot modify an unmodifiable list exception" appeared on the last line, when I was trying to generate de doc. Happy to find a solution, I hope this helps others ! |
i have this error too, how to solve? |
@PavelS0 are you still maintaining this repository? |
I found a solution. I don’t know how correct it is, but at least it works: pub.dev\archive-3.4.10\lib\src\archive.dart //List get files => UnmodifiableListView(_files); |
Solved:
change to:
because lib "archive" is used and there is a change in archive.dart with new version:
but the addFile has new behavior:
|
你好!你所说的lib\src\archive.dart是在哪个目录中,为什么我的目录中找不到呢? |
你好!你所说的此方案在哪个文件中进行修改?你能帮我解决此问题吗? |
有没有能帮忙解决此问题的大神? |
docx_template_dart/lib/src/docx_entry.dart
C:\Users\user\AppData\Local\Pub\Cache\hosted\pub.dev\docx_template-0.4.0\lib\src |
您好!非常感谢您的回复!但您给的目录结构和我的目录结构不太一样,我的是(venv) niulei@niuleideMacBook-Air my_flutter_project % which flutter /Users/niulei/Downloads/flutter/bin/flutter!请问是不是操作系统不一样的原因呢?我的电脑是mac笔记本,请问mac中对应的_updateData函数所在文件的完整的路径是多少?盼复!万分感谢! |
docx_template is a separate package! |
我怎样解决使用docx_template包时报错I/flutter (12503): Exception: Unsupported operation: Cannot modify an unmodifiable list的问题呢?您之前的建议修改docx_template_dart/lib/src/docx_entry.dart的第25行是解决此问题吗?我在mac里怎样确定您之前所述的目录并进入修改解决问题呢?并且我在pubspec.yaml中已经成功安装docx_template: ^0.3.6,但使用find ~/.pub-cache -name "docx_template" |
Code-Editor? VSCode? |
代码如下:import 'dart:io'; class PdfViewer extends StatefulWidget { const PdfViewer({Key? key, required this.template, required this.bankDetailsList}) @OverRide class _PdfViewerState extends State { @OverRide @OverRide
} Future _generatePdfFromTemplate() async {
} catch (e, stackTrace) { |
各位大神!之前的问题已解决!非常感谢! |
docx_template is not intended for displaying a Word document. The document is opened and displayed with Word or OpenOffice. |
好的,我试一下,非常感谢你🙏 |
你好!import 'dart:io'; import 'dart:typed_data'; class PdfViewer extends StatefulWidget { const PdfViewer({Key? key, required this.template, required this.bankDetailsList}) @OverRide class _PdfViewerState extends State { @OverRide @OverRide
} catch (e, stackTrace) { |
This is the wrong place for your problems. |
Found same issue today :/ |
@feimenggo your code does not work either
|
@rrsaikat could you share how did you manage at the end? |
Usage: docx_template:
git:
url: https://github.com/feimenggo/docx_template_dart |
That's what I did, |
Simply use these two at your pubspec.yml dependencies. @christenbc |
他拿的我也遇见这个错误了,flutter怎么连一个处理docx的库都没有啊,好操蛋啊 |
Future testGenerateDocxFromTemplate() async {
try {
// 从模板文件中创建 DocxTemplate 实例
final docx = await DocxTemplate.fromBytes(
await File('assets/template.docx').readAsBytes());
Content content = Content();
// 生成 Word 文档,根据传入的 Content 对象进行替换占位符
content..add(TextContent('docname', 'Simple docname'));
final docGenerated = await docx.generate(content);
print('docGenerated的类型是:${docGenerated.runtimeType}');
// 获取存储目录
final directory = await getApplicationDocumentsDirectory();
// 生成路径
final outputFile =
File('${directory.path}/generated_docx_with_replaced_content.docx');
if (docGenerated != null) {
// 写入文件
print('生成成功: ${directory.path}');
await outputFile.writeAsBytes(docGenerated);
}
} catch (e, stackTrace) {
print('Exception: $e');
print('StackTrace: $stackTrace'); // 调用方法获取堆栈跟踪
}
} 这个代码对我没效果,我的template.docx长这样
生成的docx压根也没替换掉,还长这样 |
Found same issue :
Following are the Stack Trace outputI/flutter ( 708): Unsupported operation: Cannot modify an unmodifiable list |
https://github.com/alihassan143/docx_template_dart |
An 'Unsupported operation: Cannot modify an unmodifiable list' is raised on
arch.files[_index] = ArchiveFile(_name, data.length, data);
I created a unit test following the example.
In this example an unmodifiable list exception is raised:
dart:_internal UnmodifiableListMixin.[]=
package:docx_template/src/docx_entry.dart 29:17 DocxEntry._updateData
package:docx_template/src/docx_entry.dart 58:7 DocxXmlEntry._updateArchive
package:docx_template/src/docx_entry.dart 185:13 DocxManager.updateArch.
dart:collection _LinkedHashMapMixin.forEach
package:docx_template/src/docx_entry.dart 184:10 DocxManager.updateArch
package:docx_template/src/template.dart 95:14 DocxTemplate.generate
test\utils\cv_generator_test.dart 18:37 main.
Unsupported operation: Cannot modify an unmodifiable list
I used version 0.3.6 of docx_template. I upgraded to 0.4.0 but that didn't solve the issue.
The text was updated successfully, but these errors were encountered: