cpdf_page_indicator.dart 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import 'package:compdfkit_flutter/core/cpdf_view_ctrl.dart';
  2. import 'package:flutter/material.dart';
  3. import '../dialog/cpdf_base_input_dialog_widget.dart';
  4. /// Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
  5. ///
  6. /// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  7. /// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  8. /// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  9. /// This notice may not be removed from this file.
  10. class CPDFPageIndicator extends StatefulWidget {
  11. CPDFViewCtrl ctrl;
  12. CPDFPageIndicator({required this.ctrl, super.key});
  13. @override
  14. State<CPDFPageIndicator> createState() => _CPDFPageIndicatorState();
  15. }
  16. class _CPDFPageIndicatorState extends State<CPDFPageIndicator> {
  17. int _currentPage = 0;
  18. int _pageCount = 0;
  19. bool _enterTextIsEmpty = true;
  20. @override
  21. void initState() {
  22. super.initState();
  23. _initDocumentData();
  24. setReaderViewCallback();
  25. }
  26. void _initDocumentData() async {
  27. int pageCount = await widget.ctrl.document.getPageCount();
  28. setState(() {
  29. _pageCount = pageCount;
  30. });
  31. }
  32. @override
  33. Widget build(BuildContext context) {
  34. var textStyle = const TextStyle(color: Colors.white);
  35. return GestureDetector(
  36. child: Container(
  37. decoration: const BoxDecoration(
  38. color: Color(0xCC000000),
  39. borderRadius: BorderRadius.all(Radius.circular(2))),
  40. padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 8),
  41. child: Row(
  42. mainAxisAlignment: MainAxisAlignment.center,
  43. mainAxisSize: MainAxisSize.min,
  44. children: [
  45. Text((_currentPage + 1).toString(), style: textStyle),
  46. Text('/', style: textStyle),
  47. Text(_pageCount.toString(), style: textStyle)
  48. ],
  49. ),
  50. ),
  51. onTap: () async {
  52. int? jumpPageIndex = await showDialog<int?>(
  53. context: context,
  54. builder: (BuildContext context) {
  55. return CPDFPageNavigationWidget(
  56. pageCount: _pageCount,
  57. hintText: 'Page (1/$_pageCount)',
  58. );
  59. });
  60. if (jumpPageIndex != null) {
  61. widget.ctrl.setDisplayPageIndex(jumpPageIndex);
  62. }
  63. },
  64. );
  65. }
  66. void setReaderViewCallback() {
  67. widget.ctrl.setReaderViewCallback(
  68. onMoveToChild: (pageIndex) {
  69. setState(() {
  70. _currentPage = pageIndex;
  71. });
  72. },
  73. onScrollEnd: () {},
  74. onRecordLastJumpPageNum: (pageIndex) {});
  75. }
  76. }