buildViewer method

  1. @override
Widget buildViewer()
override

Implementation

@override
Widget buildViewer() {
  if (localFilePath == null) {
    return Center(child: Text(setText('Không có dữ liệu', 'No data')));
  }

  // Using Syncfusion to render DOCX
  // Note: This requires converting DOCX to PDF first for viewing
  // Or use a webview with Google Docs Viewer

  return FutureBuilder<String>(
    future: _convertDocxToPdf(),
    builder: (context, snapshot) {
      if (snapshot.connectionState == ConnectionState.waiting) {
        return const Center(child: CircularProgressIndicator());
      }

      if (snapshot.hasError) {
        return Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              const Icon(Icons.error, size: 64, color: Colors.red),
              const SizedBox(height: 16),
              Text(setText('Lỗi hiển thị file', 'Display error')),
              const SizedBox(height: 8),
              Text(snapshot.error.toString(), textAlign: TextAlign.center),
            ],
          ),
        );
      }

      // Show PDF viewer
      return SfPdfViewer.file(
        File(snapshot.data!),
        controller: _pdfController,
        onPageChanged: (details) {
          _currentPage = details.newPageNumber;
          _totalPages = _pdfController?.pageCount ?? 1;
          rebuild();
        },
      );
    },
  );
}