SfPdfViewer.file constructor

SfPdfViewer.file(
  1. File file, {
  2. Key? key,
  3. bool canShowScrollHead = true,
  4. double pageSpacing = 4,
  5. PdfViewerController? controller,
  6. UndoHistoryController? undoController,
  7. PdfZoomLevelChangedCallback? onZoomLevelChanged,
  8. bool canShowPageLoadingIndicator = true,
  9. bool canShowScrollStatus = true,
  10. PdfPageChangedCallback? onPageChanged,
  11. bool enableDoubleTapZooming = true,
  12. bool enableTextSelection = true,
  13. PdfTextSelectionChangedCallback? onTextSelectionChanged,
  14. PdfHyperlinkClickedCallback? onHyperlinkClicked,
  15. PdfDocumentLoadedCallback? onDocumentLoaded,
  16. PdfDocumentLoadFailedCallback? onDocumentLoadFailed,
  17. PdfGestureTapCallback? onTap,
  18. PdfFormFieldValueChangedCallback? onFormFieldValueChanged,
  19. PdfFormFieldFocusChangeCallback? onFormFieldFocusChange,
  20. PdfAnnotationCallback? onAnnotationAdded,
  21. PdfAnnotationCallback? onAnnotationSelected,
  22. PdfAnnotationCallback? onAnnotationDeselected,
  23. PdfAnnotationCallback? onAnnotationEdited,
  24. PdfAnnotationCallback? onAnnotationRemoved,
  25. bool enableDocumentLinkAnnotation = true,
  26. bool canShowPaginationDialog = true,
  27. bool canShowSignaturePadDialog = true,
  28. Offset initialScrollOffset = Offset.zero,
  29. double initialZoomLevel = 1,
  30. int initialPageNumber = 1,
  31. double maxZoomLevel = 3,
  32. PdfInteractionMode interactionMode = PdfInteractionMode.selection,
  33. PdfScrollDirection? scrollDirection,
  34. PdfPageLayoutMode pageLayoutMode = PdfPageLayoutMode.continuous,
  35. Color currentSearchTextHighlightColor = const Color.fromARGB(80, 249, 125, 0),
  36. Color otherSearchTextHighlightColor = const Color.fromARGB(50, 255, 255, 1),
  37. String? password,
  38. bool canShowPasswordDialog = true,
  39. bool canShowHyperlinkDialog = true,
  40. bool enableHyperlinkNavigation = true,
  41. bool canShowTextSelectionMenu = true,
})

Creates a widget that displays the PDF document obtained from File.

Note: On Android, this may require the android.permission.READ_EXTERNAL_STORAGE permission.

class MyAppState extends State<MyApp>{
@override
void initState() {
  super.initState();
}

@override
Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: SfPdfViewer.file(
          File('/storage/emulated/0/Download/flutter-succinctly.pdf'),
        ),
      ),
    );
  }
}

Implementation

SfPdfViewer.file(
  File file, {
  Key? key,
  this.canShowScrollHead = true,
  this.pageSpacing = 4,
  this.controller,
  this.undoController,
  this.onZoomLevelChanged,
  this.canShowPageLoadingIndicator = true,
  this.canShowScrollStatus = true,
  this.onPageChanged,
  this.enableDoubleTapZooming = true,
  this.enableTextSelection = true,
  this.onTextSelectionChanged,
  this.onHyperlinkClicked,
  this.onDocumentLoaded,
  this.onDocumentLoadFailed,
  this.onTap,
  this.onFormFieldValueChanged,
  this.onFormFieldFocusChange,
  this.onAnnotationAdded,
  this.onAnnotationSelected,
  this.onAnnotationDeselected,
  this.onAnnotationEdited,
  this.onAnnotationRemoved,
  this.enableDocumentLinkAnnotation = true,
  this.canShowPaginationDialog = true,
  this.canShowSignaturePadDialog = true,
  this.initialScrollOffset = Offset.zero,
  this.initialZoomLevel = 1,
  this.initialPageNumber = 1,
  this.maxZoomLevel = 3,
  this.interactionMode = PdfInteractionMode.selection,
  this.scrollDirection,
  this.pageLayoutMode = PdfPageLayoutMode.continuous,
  this.currentSearchTextHighlightColor =
      const Color.fromARGB(80, 249, 125, 0),
  this.otherSearchTextHighlightColor = const Color.fromARGB(50, 255, 255, 1),
  this.password,
  this.canShowPasswordDialog = true,
  this.canShowHyperlinkDialog = true,
  this.enableHyperlinkNavigation = true,
  this.canShowTextSelectionMenu = true,
})  : _provider = FilePdf(file),
      // File is not supported on Flutter Web therefore neither this method.
      assert(
        !kIsWeb,
        'SfPdfViewer.file is not supported on Flutter Web. '
        'Consider using either SfPdfViewer.asset or SfPdfViewer.memory or SfPdfViewer.network instead.',
      ),
      assert(pageSpacing >= 0),
      assert(!maxZoomLevel.isNaN),
      assert(maxZoomLevel >= 1),
      super(key: key);