import 'package:compdfkit_flutter/theme/themes.dart'; import 'package:flutter/material.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 CPDFPageNavigationWidget extends StatefulWidget { int pageCount = 0; String title; String hintText; String cancelText; String positiveText; bool isDark = false; CPDFPageNavigationWidget( {required this.pageCount, this.title = 'Enter a page number', this.hintText = 'Page (1/~)', this.cancelText = 'CANCEL', this.positiveText = 'OK', this.isDark = true, super.key}); @override State createState() => _CPDFPageNavigationWidgetState(); } class _CPDFPageNavigationWidgetState extends State { bool _enable = false; final TextEditingController _controller = TextEditingController(); @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return Theme( data: widget.isDark ? comPDFKitDarkTheme : comPDFKitLightTheme, child: Builder(builder: (context) { return AlertDialog( contentPadding: const EdgeInsets.symmetric(horizontal: 24, vertical: 8), title: Text(widget.title, style: Theme.of(context).textTheme.titleMedium), content: SizedBox( width: 260, child: TextField( keyboardType: TextInputType.number, controller: _controller, decoration: textFieldStyle(context).copyWith( hintText: widget.hintText, ), onChanged: (v) { int jumpPageIndex = int.tryParse(v) ?? 0; setState(() { _enable = v.isNotEmpty && jumpPageIndex > 0 && jumpPageIndex <= widget.pageCount; }); }, ), ), actions: [ TextButton( onPressed: () { Navigator.pop(context); }, child: Text(widget.cancelText)), TextButton( onPressed: !_enable ? null : () { int pageIndex = int.tryParse(_controller.value.text) ?? 0; Navigator.pop(context, pageIndex - 1); }, child: Text( widget.positiveText, style: TextStyle(), )), ], ); })); } }