cpdf_bota_page.dart 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import 'package:compdfkit_flutter/common/util/Strings.dart';
  2. import 'package:compdfkit_flutter/core/cpdf_view_ctrl.dart';
  3. import 'package:compdfkit_flutter/widgets/common/views/cpdf_scaffold.dart';
  4. import 'package:compdfkit_flutter/widgets/viewer/pdfbota/pdfbookmark/cpdf_bookmark_page.dart';
  5. import 'package:compdfkit_flutter/widgets/viewer/pdfbota/pdfoutline/cpdf_outline_page.dart';
  6. import 'package:compdfkit_flutter/widgets/viewer/pdfbota/pdfthumbnail/cpdf_thumbnail_page.dart';
  7. import 'package:flutter/material.dart';
  8. import '../../common/views/cpdf_tool_bar.dart';
  9. /// Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
  10. ///
  11. /// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  12. /// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  13. /// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  14. /// This notice may not be removed from this file.
  15. enum CPDFBotaType { thumbnails, outline, annotations, bookmarks }
  16. class CPDFBotaPage extends StatefulWidget {
  17. final bool isDark;
  18. final List<CPDFBotaType> types;
  19. final CPDFViewCtrl ctrl;
  20. const CPDFBotaPage(
  21. {super.key,
  22. required this.ctrl,
  23. this.isDark = false,
  24. required this.types});
  25. @override
  26. State<CPDFBotaPage> createState() => _CPDFBotaPageState();
  27. }
  28. class _CPDFBotaPageState extends State<CPDFBotaPage>
  29. with SingleTickerProviderStateMixin {
  30. late TabController _tabController;
  31. final ValueNotifier<String> _title = ValueNotifier('');
  32. @override
  33. void initState() {
  34. super.initState();
  35. _title.value = titles()[0];
  36. _tabController = TabController(length: widget.types.length, vsync: this);
  37. _tabController.addListener(() {
  38. if (!_tabController.indexIsChanging) {
  39. _title.value = titles()[_tabController.index];
  40. }
  41. });
  42. }
  43. @override
  44. void dispose() {
  45. _title.dispose();
  46. _tabController.dispose();
  47. super.dispose();
  48. }
  49. @override
  50. Widget build(BuildContext context) {
  51. return CPDFScaffold(
  52. isDark: widget.isDark,
  53. appBar: CPDFToolbar(
  54. bottom: widget.types.length > 1
  55. ? TabBar(controller: _tabController, tabs: _tabItems())
  56. : null,
  57. leadingIcon: IconButton(
  58. onPressed: () {
  59. Navigator.pop(context);
  60. },
  61. icon: Icon(Icons.arrow_back,
  62. color: Theme.of(context).colorScheme.onBackground)),
  63. title: ValueListenableBuilder(
  64. builder: (BuildContext context, String title, Widget? child) {
  65. return Text(title,
  66. style: const TextStyle(
  67. fontFamily: 'sans-serif-medium', fontSize: 22));
  68. },
  69. valueListenable: _title,
  70. ),
  71. ),
  72. body: TabBarView(
  73. controller: _tabController,
  74. children: _pages(),
  75. ));
  76. }
  77. List<String> titles() {
  78. List<String> titles = widget.types.map((e) {
  79. switch (e) {
  80. case CPDFBotaType.annotations:
  81. return Strings.Annotations;
  82. case CPDFBotaType.bookmarks:
  83. return Strings.Bookmarks;
  84. case CPDFBotaType.outline:
  85. return Strings.Outlines;
  86. default:
  87. return Strings.Thumbnails;
  88. }
  89. }).toList();
  90. return titles;
  91. }
  92. List<Widget> _tabItems() {
  93. return titles().map((e) => Tab(text: e)).toList();
  94. }
  95. List<Widget> _pages() {
  96. return widget.types.map((e) {
  97. switch (e) {
  98. case CPDFBotaType.thumbnails:
  99. return CPDFThumbnailPage(
  100. isDark: widget.isDark,
  101. document: widget.ctrl.document,
  102. currentPageIndex: widget.ctrl.currentPageIndex,
  103. );
  104. // case CPDFBotaType.annotations:
  105. // return Strings.Annotations;
  106. case CPDFBotaType.bookmarks:
  107. return CPDFBookmarkPage(isDark : widget.isDark, document: widget.ctrl.document, currentPageIndex: widget.ctrl.currentPageIndex,);
  108. case CPDFBotaType.outline:
  109. return CPDFOutlinePage(document: widget.ctrl.document);
  110. default:
  111. return Text(e.name);
  112. }
  113. }).toList();
  114. }
  115. }