123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- 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<CPDFBotaType> types;
- final CPDFViewCtrl ctrl;
- const CPDFBotaPage(
- {super.key,
- required this.ctrl,
- this.isDark = false,
- required this.types});
- @override
- State<CPDFBotaPage> createState() => _CPDFBotaPageState();
- }
- class _CPDFBotaPageState extends State<CPDFBotaPage>
- with SingleTickerProviderStateMixin {
- late TabController _tabController;
- final ValueNotifier<String> _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<String> titles() {
- List<String> 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<Widget> _tabItems() {
- return titles().map((e) => Tab(text: e)).toList();
- }
- List<Widget> _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();
- }
- }
|