renderLayout method

Future<List<Widget>> renderLayout(
  1. File file
)

Implementation

Future<List<Widget>> renderLayout(File file) async {
  try {
    final archive = ZipDecoder().decodeBytes(await file.readAsBytes());

    // Extract document.xml and document.xml.rels
    final documentXmlFile = archive.files
        .where((file) => file.name == 'word/document.xml')
        .firstOrNull;
    final numberingXmlFile = archive.files
        .where((file) => file.name == 'word/numbering.xml')
        .firstOrNull;

    final relsXmlFile = archive.files
        .where((file) => file.name == 'word/_rels/document.xml.rels')
        .firstOrNull;
    // final themeXmlFIle = archive.files
    //     .where((file) => file.name == 'word/theme/theme1.xml')
    // .firstOrNull;
    final stylesXmlFile = archive.files
        .where((file) => file.name == 'word/styles.xml')
        .firstOrNull;
    if (stylesXmlFile != null) {
      final styleXml =
          XmlDocument.parse(String.fromCharCodes(stylesXmlFile.content));

      _parseStyles(styleXml);
    }
    if (documentXmlFile == null) {
      return [];
    }
    // if (themeXmlFIle != null) {
    //   final themerel =
    //       XmlDocument.parse(String.fromCharCodes(themeXmlFIle.content));
    //   // log(themerel.toXmlString());
    // }
    // Parse XML
    final documentXml =
        XmlDocument.parse(String.fromCharCodes(documentXmlFile.content));

    if (relsXmlFile != null) {
      final relsXml =
          XmlDocument.parse(String.fromCharCodes(relsXmlFile.content));
      _extractImageRelationships(relsXml, archive);
    }

    if (numberingXmlFile != null) {
      final numberingXmlContent =
          utf8.decode(numberingXmlFile.content as List<int>);
      parseNumberingDefinitions(numberingXmlContent);
    }
    // log(documentXml.toXmlString());
    // await _loadFontsFromFontTable(archive);
    // await _loadStyles(stylesXml);
    // Parse the content
    return _parseContent(
      documentXml: documentXml,
    );
  } catch (e) {
    log(e.toString());
    // Handle error, log it or provide a fallback widget

    return [
      const Text('Error parsing the document')
    ]; // Fallback widget in case of error
  }
}