1
0

pdf_page.dart 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import 'dart:developer';
  2. import 'dart:io';
  3. import 'package:flutter/material.dart';
  4. import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
  5. class PdfPage extends StatelessWidget {
  6. PdfPage({super.key, required this.params});
  7. final PdfPageParams params;
  8. final GlobalKey<SfPdfViewerState> _pdfViewerKey = GlobalKey();
  9. @override
  10. Widget build(BuildContext context) {
  11. log(params.file, name: "PdfPage");
  12. return Scaffold(
  13. appBar: AppBar(
  14. title: Text(params.title),
  15. actions: [
  16. IconButton(
  17. onPressed: () {
  18. _pdfViewerKey.currentState?.openBookmarkView();
  19. },
  20. icon: Icon(Icons.bookmark_add)),
  21. ],
  22. ),
  23. body: SfPdfViewer.file(
  24. key: _pdfViewerKey,
  25. File(params.file),
  26. // canShowPageLoadingIndicator: true,
  27. canShowScrollHead: true,
  28. canShowScrollStatus: true,
  29. enableDoubleTapZooming: true,
  30. initialZoomLevel: params.initialZoom,
  31. // maxZoomLevel: 6,
  32. ),
  33. bottomNavigationBar: (params.bottom == null)
  34. ? null
  35. : Padding(
  36. padding: const EdgeInsets.all(8.0),
  37. child: params.bottom,
  38. ),
  39. );
  40. }
  41. }
  42. class PdfPageParams {
  43. const PdfPageParams(
  44. {required this.file,
  45. required this.title,
  46. this.bottom,
  47. this.initialZoom = 3});
  48. final String title;
  49. final String file;
  50. final Widget? bottom;
  51. final double initialZoom;
  52. }