cpdf_readerview_page.dart 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import 'package:compdfkit_flutter/theme/colors.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import '../core/cpdf_view_ctrl.dart';
  5. import '../cpdf_configuration.dart';
  6. import '../theme/themes.dart';
  7. import 'common/pdfview/cpdf_page_indicator.dart';
  8. import 'common/pdfview/cpdf_page_slider_bar.dart';
  9. import 'common/pdfview/cpdf_reader_widget.dart';
  10. import 'common/slider/cpdf_slider_theme.dart';
  11. import 'common/views/cpdf_main_tool_bar.dart';
  12. /// Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
  13. ///
  14. /// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  15. /// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  16. /// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  17. /// This notice may not be removed from this file.
  18. class CPDFReaderViewPage extends StatefulWidget {
  19. final bool isDark;
  20. const CPDFReaderViewPage({super.key, this.isDark = false});
  21. @override
  22. State<CPDFReaderViewPage> createState() => _CPDFReaderViewPageState();
  23. }
  24. class _CPDFReaderViewPageState extends State<CPDFReaderViewPage>
  25. with SingleTickerProviderStateMixin {
  26. CPDFViewCtrl? ctrl;
  27. bool _isNormalMode = true;
  28. late final AnimationController _controller;
  29. @override
  30. void initState() {
  31. super.initState();
  32. _controller = AnimationController(
  33. vsync: this, duration: const Duration(milliseconds: 300));
  34. }
  35. @override
  36. Widget build(BuildContext context) {
  37. return MaterialApp(
  38. theme: comPDFKitLightTheme,
  39. darkTheme: comPDFKitDarkTheme,
  40. themeMode: widget.isDark ? ThemeMode.dark : ThemeMode.light,
  41. home: Scaffold(
  42. primary: _isNormalMode,
  43. appBar: PreferredSize(
  44. preferredSize: const Size(0, 0),
  45. child: Builder(builder: (context) {
  46. return AppBar(
  47. systemOverlayStyle: SystemUiOverlayStyle(
  48. systemNavigationBarColor:
  49. Theme.of(context).scaffoldBackgroundColor),
  50. backgroundColor:
  51. widget.isDark ? null : CPDFColors.backgroundLight,
  52. elevation: 0,
  53. );
  54. })),
  55. body: Column(
  56. children: [
  57. if (ctrl != null) ...{
  58. CPDFMainToolbar(
  59. visible: _isNormalMode,
  60. controller: _controller,
  61. ctrl: ctrl!,
  62. isDark: widget.isDark)
  63. },
  64. Expanded(
  65. child: Stack(
  66. alignment: Alignment.center,
  67. children: [
  68. CPDFReaderWidget(
  69. documentPath: "",
  70. configuration: CPDFConfiguration(),
  71. onComPDFKitWidgetCreate: (ctrl) {
  72. setState(() {
  73. this.ctrl = ctrl;
  74. setReaderViewCallback();
  75. });
  76. },
  77. ),
  78. if (ctrl != null) ...{
  79. Positioned(
  80. bottom: 20,
  81. child: AnimatedOpacity(
  82. opacity: _isNormalMode ? 1.0 : 0.0,
  83. duration: const Duration(milliseconds: 300),
  84. curve: Curves.fastOutSlowIn,
  85. child: CPDFPageIndicator(
  86. ctrl: ctrl!,
  87. isDark: widget.isDark,
  88. ),
  89. )),
  90. Positioned(
  91. right: 0,
  92. top: 0,
  93. bottom: 0,
  94. child: AnimatedOpacity(
  95. opacity: _isNormalMode ? 1.0 : 0.0,
  96. duration: const Duration(milliseconds: 300),
  97. curve: Curves.fastOutSlowIn,
  98. child: CPDFPageNavigationSliderBar(
  99. ctrl: ctrl!,
  100. position: CPDFSliderIndicatorPosition.right),
  101. )),
  102. },
  103. ],
  104. ))
  105. ],
  106. )),
  107. );
  108. }
  109. void setReaderViewCallback() {
  110. ctrl!.onTapMainDocArea.stream.listen((event) {
  111. setState(() {
  112. _isNormalMode = !_isNormalMode;
  113. });
  114. });
  115. }
  116. }