import 'package:flutter/material.dart'; import 'package:kmpdfkit_demo/widgets/contains.dart'; import 'package:kmpdfkit_demo/widgets/function/attrwidget/attr_free_text_widget.dart'; import 'package:kmpdfkit_demo/widgets/function/attrwidget/attr_link_widget.dart'; import 'package:kmpdfkit_demo/widgets/function/attrwidget/signature/attr_signature_list_widget.dart'; import 'package:kmpdfkit_demo/widgets/function/attrwidget/stamp/attr_stamp_widget.dart'; import 'package:kmpdfkit_demo/widgets/function/attrwidget/base_slider_widget.dart'; import 'package:kmpdfkit_demo/widgets/function/attrwidget/attr_color_list_widget.dart'; import 'package:kmpdfkit_demo/widgets/function/attrwidget/ink/attr_ink_pen_wave_widget.dart'; import 'package:kmpdfkit_demo/widgets/function/attrwidget/ink/attr_ink_line_width_widget.dart'; import 'package:kmpdfkit_demo/widgets/function/attrwidget/attr_shape_type_widget.dart'; import 'package:kmpdfkit_demo/widgets/models/annot_attribute_bean.dart'; import 'package:kmpdfkit_demo/widgets/models/annot_bean.dart'; import 'package:kmpdfkit_demo/widgets/models/text_stamp_bean.dart'; /// annot_attribute_options_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. typedef AnnotAttributeOptionsCallback = void Function(AnnotAttributeBean); class AnnotAttributeOptionsWidget extends StatefulWidget { AnnotBean annotBean; final AnnotAttributeOptionsCallback attributeOptionsCallback; AnnotAttributeOptionsWidget( {Key? key, required this.annotBean, required this.attributeOptionsCallback}) : super(key: key); @override State createState() => _AnnotAttributeOptionsWidgetState(); } class _AnnotAttributeOptionsWidgetState extends State { @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return annotationAttrWidget(); } Widget annotationAttrWidget() { switch (widget.annotBean.annotType) { case AnnotationType.highlight: case AnnotationType.underline: case AnnotationType.squiggly: case AnnotationType.strikeout: { return Column( mainAxisSize: MainAxisSize.min, children: [_colorWidget(), _colorAlphaWidget()]); } case AnnotationType.ink: { return Column(mainAxisSize: MainAxisSize.min, children: [ InkCurvedWidget( color: widget.annotBean.attributeBean.color, lineWidth: widget.annotBean.attributeBean.borderWidth, alpha: widget.annotBean.attributeBean.alpha, ), _colorWidget(), _colorAlphaWidget(), _inkPenSwitchWidget() ]); } case AnnotationType.shape: { return Column(mainAxisSize: MainAxisSize.min, children: [ ShapeAttrWidget( bean: widget.annotBean.attributeBean, callback: (AnnotAttributeBean? bean) { if (bean != null) { widget.annotBean.attributeBean = bean; } widget.attributeOptionsCallback(widget.annotBean.attributeBean); }, ) ]); } case AnnotationType.freetext: { return Column(mainAxisSize: MainAxisSize.min, children: [ AttrFreeTextWidget( bean: widget.annotBean.attributeBean, callback: widget.attributeOptionsCallback, ) ]); } case AnnotationType.signature: { return AttrSignatureListWidget( callback: (imagePath) { widget.annotBean.attributeBean ..imagePath = imagePath ..isSignature = true; widget.attributeOptionsCallback(widget.annotBean.attributeBean); Navigator.pop(context); }, ); } case AnnotationType.stamp: { return AttrStampWidget(callback: (String? standardStampName, TextStampBean? textStampBean) { if (standardStampName != null) { widget.annotBean.attributeBean ..standardStampName = standardStampName ..customStampBean = null; } if (textStampBean != null) { widget.annotBean.attributeBean ..standardStampName = '' ..customStampBean = textStampBean; } widget.attributeOptionsCallback(widget.annotBean.attributeBean); Navigator.pop(context); }); } case AnnotationType.link: { return AttrLinkWidget( attributeBean: widget.annotBean.attributeBean, callback: (LinkType linkType, String linkWeb, int linkPage, String linkEmail) { widget.annotBean.attributeBean ..linkType = linkType ..linkWeb = linkWeb ..linkPage = linkPage ..linkEmail = linkEmail; widget.attributeOptionsCallback(widget.annotBean.attributeBean); }, cancelCreateCallback: (cancelCreateLink) { widget.annotBean.attributeBean.cancelCreateLink = cancelCreateLink; widget.attributeOptionsCallback(widget.annotBean.attributeBean); }, ); } default: return const Placeholder(); } } Widget _colorWidget() { return ColorListWidget( color: widget.annotBean.attributeBean.color, colorOptionsCallback: (color) { setState(() { widget.annotBean.attributeBean.color = color; }); widget.attributeOptionsCallback(widget.annotBean.attributeBean); }); } Widget _colorAlphaWidget() { return colorAlphaWidget( currentAlphaValue: widget.annotBean.attributeBean.alpha, alphaOptionsCallback: (value) { setState(() { widget.annotBean.attributeBean.alpha = value.round(); }); widget.attributeOptionsCallback(widget.annotBean.attributeBean); }); } Widget _inkPenSwitchWidget() { return InkPenLineWidthWidget( borderWidth: widget.annotBean.attributeBean.borderWidth, inkBorderWidthCallback: (borderWidth) { setState(() { widget.annotBean.attributeBean.borderWidth = borderWidth; widget.attributeOptionsCallback(widget.annotBean.attributeBean); }); }); } }