import 'package:compdfkit_flutter/common/util/Strings.dart'; import 'package:compdfkit_flutter/core/cpdf_view_ctrl.dart'; import 'package:compdfkit_flutter/widgets/common/views/cpdf_scaffold.dart'; import 'package:compdfkit_flutter/widgets/viewer/pdfbota/pdfbookmark/cpdf_bookmark_page.dart'; import 'package:compdfkit_flutter/widgets/viewer/pdfbota/pdfoutline/cpdf_outline_page.dart'; import 'package:compdfkit_flutter/widgets/viewer/pdfbota/pdfthumbnail/cpdf_thumbnail_page.dart'; import 'package:flutter/material.dart'; import '../../common/views/cpdf_tool_bar.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. enum CPDFBotaType { thumbnails, outline, annotations, bookmarks } class CPDFBotaPage extends StatefulWidget { final bool isDark; final List types; final CPDFViewCtrl ctrl; const CPDFBotaPage( {super.key, required this.ctrl, this.isDark = false, required this.types}); @override State createState() => _CPDFBotaPageState(); } class _CPDFBotaPageState extends State with SingleTickerProviderStateMixin { late TabController _tabController; final ValueNotifier _title = ValueNotifier(''); @override void initState() { super.initState(); _title.value = titles()[0]; _tabController = TabController(length: widget.types.length, vsync: this); _tabController.addListener(() { if (!_tabController.indexIsChanging) { _title.value = titles()[_tabController.index]; } }); } @override void dispose() { _title.dispose(); _tabController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return CPDFScaffold( isDark: widget.isDark, appBar: CPDFToolbar( bottom: widget.types.length > 1 ? TabBar(controller: _tabController, tabs: _tabItems()) : null, leadingIcon: IconButton( onPressed: () { Navigator.pop(context); }, icon: Icon(Icons.arrow_back, color: Theme.of(context).colorScheme.onBackground)), title: ValueListenableBuilder( builder: (BuildContext context, String title, Widget? child) { return Text(title, style: const TextStyle( fontFamily: 'sans-serif-medium', fontSize: 22)); }, valueListenable: _title, ), ), body: TabBarView( controller: _tabController, children: _pages(), )); } List titles() { List titles = widget.types.map((e) { switch (e) { case CPDFBotaType.annotations: return Strings.Annotations; case CPDFBotaType.bookmarks: return Strings.Bookmarks; case CPDFBotaType.outline: return Strings.Outlines; default: return Strings.Thumbnails; } }).toList(); return titles; } List _tabItems() { return titles().map((e) => Tab(text: e)).toList(); } List _pages() { return widget.types.map((e) { switch (e) { case CPDFBotaType.thumbnails: return CPDFThumbnailPage( isDark: widget.isDark, document: widget.ctrl.document, currentPageIndex: widget.ctrl.currentPageIndex, ); // case CPDFBotaType.annotations: // return Strings.Annotations; case CPDFBotaType.bookmarks: return CPDFBookmarkPage(isDark : widget.isDark, document: widget.ctrl.document, currentPageIndex: widget.ctrl.currentPageIndex,); case CPDFBotaType.outline: return CPDFOutlinePage(document: widget.ctrl.document); default: return Text(e.name); } }).toList(); } }