From 3757368a006c0737be64ddf798f556fe42dad72a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6sche?= Date: Wed, 14 Jan 2026 11:48:07 +0100 Subject: [PATCH] Refactor DOCX file generation to simplify path handling and enhance document styles --- b0esche_cloud/lib/services/file_service.dart | 67 +++++++++++++++----- 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/b0esche_cloud/lib/services/file_service.dart b/b0esche_cloud/lib/services/file_service.dart index 5037296..6bad05c 100644 --- a/b0esche_cloud/lib/services/file_service.dart +++ b/b0esche_cloud/lib/services/file_service.dart @@ -258,19 +258,9 @@ class FileService { // Generate minimal valid DOCX file (Office Open XML format) final bytes = _generateEmptyDocx(); - // Construct proper path - String fullPath; - if (parentPath == '/') { - fullPath = '/$docxName'; - } else { - final cleanParent = parentPath.endsWith('/') - ? parentPath.substring(0, parentPath.length - 1) - : parentPath; - fullPath = '$cleanParent/$docxName'; - } - + // Send parent directory as 'path' parameter final formData = FormData.fromMap({ - 'path': fullPath, + 'path': parentPath, 'file': MultipartFile.fromBytes(bytes, filename: docxName), }); @@ -296,6 +286,7 @@ class FileService { + '''; archive.addFile( ArchiveFile( @@ -321,13 +312,17 @@ class FileService { // word/document.xml - the actual document content (empty) const documentXml = ''' - + - - - + + + + + + + '''; archive.addFile( @@ -338,6 +333,46 @@ class FileService { ), ); + // word/styles.xml - document styles + const stylesXml = ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +'''; + archive.addFile( + ArchiveFile( + 'word/styles.xml', + stylesXml.length, + Uint8List.fromList(stylesXml.codeUnits), + ), + ); + // word/_rels/document.xml.rels - document relationships (empty but required) const docRels = '''