123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- import 'package:compdfkit_flutter/common/util/Strings.dart';
- 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.
- Future<String?> showCPDFInputDialog(BuildContext context,
- {bool isDark = false,
- String title = '',
- String? text,
- String hintText = '',
- String? cancelText,
- String positiveText = '',
- VoidCallback? onCancel,
- ValueChanged<String>? onPositive}) async {
- String? value = await showDialog<String>(
- context: context,
- builder: (context) {
- return CPDFInputDialogWidget(
- title: title,
- text: text,
- isDark: isDark,
- hintText: hintText,
- cancelText: cancelText,
- positiveText: positiveText,
- onCancel: onCancel,
- onPositive: onPositive);
- });
- return value;
- }
- class CPDFInputDialogWidget extends StatefulWidget {
- final String title;
- final String hintText;
- final String? text;
- final String? cancelText;
- final String positiveText;
- final bool isDark;
- final VoidCallback? onCancel;
- final ValueChanged<String>? onPositive;
- const CPDFInputDialogWidget(
- {this.title = '',
- this.text,
- this.hintText = '',
- this.cancelText,
- this.positiveText = Strings.OK,
- this.isDark = false,
- this.onCancel,
- this.onPositive,
- super.key});
- @override
- State<CPDFInputDialogWidget> createState() => _CPDFInputDialogWidgetState();
- }
- class _CPDFInputDialogWidgetState extends State<CPDFInputDialogWidget> {
- final TextEditingController _controller = TextEditingController();
- @override
- void initState() {
- super.initState();
- if (widget.text != null) {
- _controller.text = widget.text!;
- }
- }
- @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) {},
- ),
- ),
- actions: <Widget>[
- if (widget.cancelText != null) ...{
- TextButton(
- onPressed: () {
- if (widget.onCancel != null) {
- widget.onCancel!();
- }
- },
- child: Text(widget.cancelText!))
- },
- TextButton(
- onPressed: () {
- if (widget.onPositive != null) {
- widget.onPositive!(_controller.text);
- }
- },
- child: Text(
- widget.positiveText,
- )),
- ],
- );
- }));
- }
- }
|