cpdf_main_tool_bar.dart 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import 'package:compdfkit_flutter/core/cpdf_view_ctrl.dart';
  2. import 'package:compdfkit_flutter/theme/colors.dart';
  3. import 'package:compdfkit_flutter/theme/themes.dart';
  4. import 'package:compdfkit_flutter/widgets/viewer/pdfbota/cpdf_bota_page.dart';
  5. import 'package:flutter/material.dart';
  6. import '../../viewer/pdfbota/pdfthumbnail/cpdf_thumbnail_page.dart';
  7. /// Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
  8. ///
  9. /// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  10. /// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  11. /// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  12. /// This notice may not be removed from this file.
  13. class CPDFSlidingMainToolbar extends CPDFMainToolbar {
  14. final bool visible;
  15. final AnimationController controller;
  16. CPDFSlidingMainToolbar(
  17. {super.key,
  18. required this.visible,
  19. required this.controller,
  20. required super.ctrl,
  21. super.isDark,
  22. super.actions});
  23. CPDFSlidingMainToolbar.normal(
  24. {required this.visible,
  25. required this.controller,
  26. required super.ctrl,
  27. super.isDark})
  28. : super.normal();
  29. @override
  30. Widget build(BuildContext context) {
  31. visible ? controller.reverse() : controller.forward();
  32. return SlideTransition(
  33. position: Tween(begin: Offset.zero, end: const Offset(0, -1)).animate(
  34. CurvedAnimation(parent: controller, curve: Curves.fastOutSlowIn)),
  35. child: visible ? super.build(context) : null);
  36. }
  37. // @override
  38. // Size get preferredSize =>
  39. // visible ? super.preferredSize : Size(super.preferredSize.width, 0.0);
  40. }
  41. class CPDFMainToolbar extends StatelessWidget implements PreferredSizeWidget {
  42. final CPDFViewCtrl ctrl;
  43. List<CPDFActionWidget>? actions;
  44. bool isDark = false;
  45. CPDFMainToolbar(
  46. {Key? key, required this.ctrl, this.isDark = false, this.actions})
  47. : super(key: key);
  48. CPDFMainToolbar.normal({Key? key, this.isDark = false, required this.ctrl})
  49. : super(key: key) {
  50. actions = [
  51. CPDFActions.thumbnail(onPressed: (context) async {
  52. pushToBota(context, const [CPDFBotaType.thumbnails, CPDFBotaType.outline]);
  53. }),
  54. CPDFActions.search(),
  55. CPDFActions.bota(onPressed: (context) {
  56. pushToBota(context, const [CPDFBotaType.outline]);
  57. }),
  58. CPDFActions.more()
  59. ];
  60. }
  61. void pushToBota(BuildContext context, List<CPDFBotaType> types) async {
  62. int? pageIndex = await Navigator.push(context, MaterialPageRoute(builder: (_) {
  63. return CPDFBotaPage(
  64. ctrl: ctrl,
  65. isDark: isDark,
  66. types: types,
  67. );
  68. }));
  69. if (pageIndex != null) {
  70. ctrl.setDisplayPageIndex(pageIndex);
  71. }
  72. }
  73. @override
  74. Widget build(BuildContext context) {
  75. return Theme(
  76. data: isDark
  77. ? comPDFKitDarkTheme
  78. : comPDFKitLightTheme.copyWith(
  79. colorScheme: comPDFKitLightTheme.colorScheme
  80. .copyWith(primary: const Color(0xFFFAFCFF))),
  81. child: Builder(builder: (context) {
  82. return AppBar(
  83. leading: null,
  84. title: Row(
  85. children: [
  86. InkWell(
  87. borderRadius: BorderRadius.circular(6),
  88. child: Padding(
  89. padding: const EdgeInsets.only(
  90. left: 8, right: 8, top: 8, bottom: 8),
  91. child: Text('Viewer',
  92. style: Theme.of(context)
  93. .textTheme
  94. .titleLarge
  95. ?.copyWith(fontFamily: 'sans-serif-medium'))),
  96. onTap: () {},
  97. ),
  98. ],
  99. ),
  100. titleSpacing: 10,
  101. elevation: 2,
  102. actions: actions,
  103. );
  104. }));
  105. }
  106. @override
  107. Size get preferredSize => const Size(double.infinity, 56);
  108. }
  109. class CPDFActions {
  110. static CPDFActionWidget thumbnail({CPDFActionOnPressedCallback? onPressed}) {
  111. return CPDFActionWidget(
  112. image: 'assets/images/ic_thumbnail.png',
  113. package: 'compdfkit_flutter',
  114. onPressed: onPressed,
  115. );
  116. }
  117. static CPDFActionWidget search({CPDFActionOnPressedCallback? onPressed}) {
  118. return CPDFActionWidget(
  119. image: 'assets/images/ic_search.png',
  120. package: 'compdfkit_flutter',
  121. onPressed: onPressed,
  122. );
  123. }
  124. static CPDFActionWidget bota({CPDFActionOnPressedCallback? onPressed}) {
  125. return CPDFActionWidget(
  126. image: 'assets/images/ic_book.png',
  127. package: 'compdfkit_flutter',
  128. onPressed: onPressed,
  129. );
  130. }
  131. static CPDFActionWidget more({CPDFActionOnPressedCallback? onPressed}) {
  132. return CPDFActionWidget(
  133. image: 'assets/images/ic_more.png',
  134. package: 'compdfkit_flutter',
  135. onPressed: onPressed,
  136. );
  137. }
  138. }
  139. typedef CPDFActionOnPressedCallback = Function(BuildContext context);
  140. class CPDFActionWidget extends StatelessWidget {
  141. final String image;
  142. final String package;
  143. final CPDFActionOnPressedCallback? onPressed;
  144. const CPDFActionWidget(
  145. {Key? key,
  146. required this.image,
  147. this.package = 'compdfkit_flutter',
  148. this.onPressed})
  149. : super(key: key);
  150. @override
  151. Widget build(BuildContext context) {
  152. return IconButton(
  153. splashRadius: 24,
  154. onPressed: () {
  155. if (onPressed != null) {
  156. onPressed!(context);
  157. }
  158. },
  159. icon: Image.asset(
  160. image,
  161. package: package,
  162. width: 24,
  163. height: 24,
  164. color: Theme.of(context).colorScheme.onBackground,
  165. ));
  166. }
  167. }