1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- import 'package:compdfkit_flutter/core/cpdf_view_ctrl.dart';
- import 'package:flutter/material.dart';
- import '../dialog/cpdf_base_input_dialog_widget.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 CPDFPageIndicator extends StatefulWidget {
- final CPDFViewCtrl ctrl;
- Decoration? decoration;
- TextStyle? textStyle;
- CPDFPageIndicator(
- {required this.ctrl, this.decoration, this.textStyle, super.key}) {
- decoration ??= const BoxDecoration(
- color: Color(0xCC000000),
- borderRadius: BorderRadius.all(Radius.circular(2)));
- textStyle ??= const TextStyle(color: Colors.white);
- }
- @override
- State<CPDFPageIndicator> createState() => _CPDFPageIndicatorState();
- }
- class _CPDFPageIndicatorState extends State<CPDFPageIndicator> {
- int _pageCount = 0;
- @override
- void initState() {
- super.initState();
- _initDocumentData();
- }
- void _initDocumentData() async {
- widget.ctrl.document.getPageCount().then((value) {
- setState(() {
- _pageCount = value;
- });
- });
- }
- @override
- Widget build(BuildContext context) {
- return GestureDetector(
- child: Container(
- decoration: widget.decoration,
- padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 8),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- mainAxisSize: MainAxisSize.min,
- children: [
- StreamBuilder(
- initialData: 1,
- stream: widget.ctrl.currentPageIndexStream.stream,
- builder: (context, pageIndex) {
- return Text((pageIndex.data! + 1).toString(),
- style: widget.textStyle);
- }),
- Text('/', style: widget.textStyle),
- Text(_pageCount.toString(), style: widget.textStyle)
- ],
- ),
- ),
- onTap: () async {
- int? jumpPageIndex = await showDialog<int?>(
- context: context,
- builder: (BuildContext context) {
- return CPDFPageNavigationWidget(
- pageCount: _pageCount,
- hintText: 'Page (1/$_pageCount)',
- );
- });
- if (jumpPageIndex != null) {
- widget.ctrl.setDisplayPageIndex(jumpPageIndex);
- }
- },
- );
- }
- }
|