import 'package:compdfkit_flutter/core/cpdf_view_ctrl.dart'; import 'package:compdfkit_flutter/theme/colors.dart'; import 'package:compdfkit_flutter/theme/themes.dart'; import 'package:compdfkit_flutter/widgets/viewer/pdfbota/cpdf_bota_page.dart'; import 'package:flutter/material.dart'; import '../../viewer/pdfbota/pdfthumbnail/cpdf_thumbnail_page.dart'; /// Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved. /// /// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW /// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT. /// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES. /// This notice may not be removed from this file. class CPDFSlidingMainToolbar extends CPDFMainToolbar { final bool visible; final AnimationController controller; CPDFSlidingMainToolbar( {super.key, required this.visible, required this.controller, required super.ctrl, super.isDark, super.actions}); CPDFSlidingMainToolbar.normal( {required this.visible, required this.controller, required super.ctrl, super.isDark}) : super.normal(); @override Widget build(BuildContext context) { visible ? controller.reverse() : controller.forward(); return SlideTransition( position: Tween(begin: Offset.zero, end: const Offset(0, -1)).animate( CurvedAnimation(parent: controller, curve: Curves.fastOutSlowIn)), child: visible ? super.build(context) : null); } // @override // Size get preferredSize => // visible ? super.preferredSize : Size(super.preferredSize.width, 0.0); } class CPDFMainToolbar extends StatelessWidget implements PreferredSizeWidget { final CPDFViewCtrl ctrl; List? actions; bool isDark = false; CPDFMainToolbar( {Key? key, required this.ctrl, this.isDark = false, this.actions}) : super(key: key); CPDFMainToolbar.normal({Key? key, this.isDark = false, required this.ctrl}) : super(key: key) { actions = [ CPDFActions.thumbnail(onPressed: (context) async { pushToBota(context, const [CPDFBotaType.thumbnails, CPDFBotaType.outline]); }), CPDFActions.search(), CPDFActions.bota(onPressed: (context) { pushToBota(context, const [CPDFBotaType.outline]); }), CPDFActions.more() ]; } void pushToBota(BuildContext context, List types) async { int? pageIndex = await Navigator.push(context, MaterialPageRoute(builder: (_) { return CPDFBotaPage( ctrl: ctrl, isDark: isDark, types: types, ); })); if (pageIndex != null) { ctrl.setDisplayPageIndex(pageIndex); } } @override Widget build(BuildContext context) { return Theme( data: isDark ? comPDFKitDarkTheme : comPDFKitLightTheme.copyWith( colorScheme: comPDFKitLightTheme.colorScheme .copyWith(primary: const Color(0xFFFAFCFF))), child: Builder(builder: (context) { return AppBar( leading: null, title: Row( children: [ InkWell( borderRadius: BorderRadius.circular(6), child: Padding( padding: const EdgeInsets.only( left: 8, right: 8, top: 8, bottom: 8), child: Text('Viewer', style: Theme.of(context) .textTheme .titleLarge ?.copyWith(fontFamily: 'sans-serif-medium'))), onTap: () {}, ), ], ), titleSpacing: 10, elevation: 2, actions: actions, ); })); } @override Size get preferredSize => const Size(double.infinity, 56); } class CPDFActions { static CPDFActionWidget thumbnail({CPDFActionOnPressedCallback? onPressed}) { return CPDFActionWidget( image: 'assets/images/ic_thumbnail.png', package: 'compdfkit_flutter', onPressed: onPressed, ); } static CPDFActionWidget search({CPDFActionOnPressedCallback? onPressed}) { return CPDFActionWidget( image: 'assets/images/ic_search.png', package: 'compdfkit_flutter', onPressed: onPressed, ); } static CPDFActionWidget bota({CPDFActionOnPressedCallback? onPressed}) { return CPDFActionWidget( image: 'assets/images/ic_book.png', package: 'compdfkit_flutter', onPressed: onPressed, ); } static CPDFActionWidget more({CPDFActionOnPressedCallback? onPressed}) { return CPDFActionWidget( image: 'assets/images/ic_more.png', package: 'compdfkit_flutter', onPressed: onPressed, ); } } typedef CPDFActionOnPressedCallback = Function(BuildContext context); class CPDFActionWidget extends StatelessWidget { final String image; final String package; final CPDFActionOnPressedCallback? onPressed; const CPDFActionWidget( {Key? key, required this.image, this.package = 'compdfkit_flutter', this.onPressed}) : super(key: key); @override Widget build(BuildContext context) { return IconButton( splashRadius: 24, onPressed: () { if (onPressed != null) { onPressed!(context); } }, icon: Image.asset( image, package: package, width: 24, height: 24, color: Theme.of(context).colorScheme.onBackground, )); } }