We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
package version: 1.0.7 ios version: 16.4
enum _PdfState { loading, success, error, } class PdfView extends StatefulWidget { final Uint8List bytes; final VoidCallback onZoomed; final VoidCallback onZoomReset; const PdfView({ required this.bytes, required this.onZoomed, required this.onZoomReset, super.key, }); @override State<PdfView> createState() => _PdfViewState(); } class _PdfViewState extends State<PdfView> { _PdfState _state = _PdfState.loading; late PDFDocument _document; late final String _cacheFileRelativePath = 'pdf_view/$hashCode.pdf'; @override void initState() { super.initState(); _loadDocument(); } @override void dispose() { PDFDocument.clearPreviewCache(); _clearCache(); super.dispose(); } @override Widget build(BuildContext context) { switch (_state) { case _PdfState.loading: return const Center( child: DocumentLoader(), ); case _PdfState.success: return PDFViewer( document: _document, scrollDirection: Axis.vertical, showIndicator: true, showPicker: false, showNavigation: false, onZoomChanged: (scale) { if (scale == 1) { widget.onZoomReset(); } else { widget.onZoomed(); } }, ); case _PdfState.error: return DocumentError( onRetry: _loadDocument, ); } } Future<void> _clearCache() async { final Directory cacheDirectory = await getDocumentViewerCacheDirectory(); final file = File(path.join( cacheDirectory.path, _cacheFileRelativePath, )); if (file.existsSync()) { file.deleteSync(); } } Future<File> _writeBytesToFile() async { final Directory cacheDirectory = await getDocumentViewerCacheDirectory(); return File(path.join( cacheDirectory.path, _cacheFileRelativePath, )) ..createSync(recursive: true) ..writeAsBytesSync(widget.bytes); } Future<void> _loadDocument() async { try { setState(() { _state = _PdfState.loading; }); final File file = await _writeBytesToFile(); _document = await PDFDocument.fromFile( file, clearPreviewCache: false, ); setState(() { _state = _PdfState.success; }); } catch (_) { setState(() { _state = _PdfState.error; }); } } }
The text was updated successfully, but these errors were encountered:
@kaichii
Sorry, something went wrong.
@shabanov-krl Thanks for your patience, I'll check this issue later.
i have the same problem :( , something new?
No branches or pull requests
package version: 1.0.7
ios version: 16.4
mix_pages.mov
The text was updated successfully, but these errors were encountered: