displayWordFile method

Future<List<Widget>> displayWordFile(
  1. String fileType,
  2. Document wordDocument,
  3. List<Styles> stylesList,
  4. List<FootEndNote> footNotes,
  5. List<FootEndNote> endNotes,
)

Function for displaying .docx file

Implementation

Future<List<Widget>> displayWordFile(
    String fileType, Document wordDocument, List<Styles> stylesList, List<FootEndNote> footNotes, List<FootEndNote> endNotes) async {
  List<Widget> tempList = [];
  if (fileType == "word") {
    for (int i = 0; i < wordDocument.pages.length; i++) {
      List<Widget> pageWidgets = [];
      for (int j = 0; j < wordDocument.pages[i].components.length; j++) {
        List<Widget> tempPageWidgets =
            await compute(getComponents, GetComponentsParams(wordDocument.pages[i].components[j], stylesList, pageWidgets, wordDocument));
        pageWidgets.addAll(tempPageWidgets);
      }
      if (wordDocument.pages[i].footNotes.isNotEmpty) {
        for (var footNt in wordDocument.pages[i].footNotes) {
          var chkFootNot = footNotes.firstWhereOrNull((ftNt) {
            return ftNt.id == footNt["id"];
          });
          if (chkFootNot != null) {
            pageWidgets.add(getFootEndNote(chkFootNot, stylesList, footNt["refNo"]!));
          }
        }
      }
      if (wordDocument.pages[i].endNotes.isNotEmpty) {
        for (var endNt in wordDocument.pages[i].endNotes) {
          var chkEndNt = endNotes.firstWhereOrNull((edNt) {
            return edNt.id == endNt["id"];
          });
          if (chkEndNt != null) {
            pageWidgets.add(getFootEndNote(chkEndNt, stylesList, endNt["refNo"]!));
          }
        }
      }
      tempList.add(Container(
        color: Colors.white,
        constraints: BoxConstraints(minHeight: wordDocument.pageSize.height, minWidth: wordDocument.pageSize.width),
        margin: const EdgeInsets.all(8),
        child: Padding(
          padding: EdgeInsets.only(
              left: wordDocument.pageMargin["leftMar"] ?? 0,
              right: wordDocument.pageMargin["rightMar"] ?? 0,
              top: wordDocument.pageMargin["topMar"] ?? 0,
              bottom: wordDocument.pageMargin["bottomMar"] ?? 0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: pageWidgets,
          ),
        ),
      ));
    }
  }
  return tempList;
}