import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:kmpdfkit_demo/widgets/constains.dart'; import 'package:kmpdfkit_demo/widgets/events.dart'; import 'package:kmpdfkit_demo/widgets/function/annot_attribute_options_widget.dart'; import 'package:kmpdfkit_demo/widgets/function/attrwidget/attr_signature_list_widget.dart'; import 'package:kmpdfkit_demo/widgets/models/annot_attribute_bean.dart'; import 'package:kmpdfkit_demo/widgets/models/annot_bean.dart'; /// pdf_bottom_annot_fun_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 PDFBottomAnnotFunWidget extends StatefulWidget { const PDFBottomAnnotFunWidget({Key? key}) : super(key: key); @override State createState() => _PDFBottomAnnotFunWidgetState(); } class _PDFBottomAnnotFunWidgetState extends State { AnnotationType selectAnnot = AnnotationType.unknown; var annotFunList = [ AnnotBean( annotType: AnnotationType.highlight, normalImagePath: 'assets/images/ic_reader_highlight.svg', selectImagePath: 'assets/images/ic_reader_highlight_select.svg', attributeBean: AnnotAttributeBean(color: Colors.red), ), AnnotBean( annotType: AnnotationType.underline, normalImagePath: 'assets/images/ic_reader_underline.svg', selectImagePath: 'assets/images/ic_reader_underline_select.svg', attributeBean: AnnotAttributeBean(color: Colors.blue)), AnnotBean( annotType: AnnotationType.strikeout, normalImagePath: 'assets/images/ic_reader_strikethrough.svg', selectImagePath: 'assets/images/ic_reader_strikethrough_select.svg', attributeBean: AnnotAttributeBean(color: Colors.green)), AnnotBean( annotType: AnnotationType.squiggly, normalImagePath: 'assets/images/ic_reader_squiggly_underline.svg', selectImagePath: 'assets/images/ic_reader_squiggly_underline_select.svg', attributeBean: AnnotAttributeBean(color: Colors.pink)), AnnotBean( annotType: AnnotationType.ink, normalImagePath: 'assets/images/ic_reader_ink.svg', selectImagePath: 'assets/images/ic_reader_ink_select.svg', attributeBean: AnnotAttributeBean(color: Colors.yellow)), AnnotBean( annotType: AnnotationType.shape, normalImagePath: 'assets/images/ic_reader_shape.svg', selectImagePath: 'assets/images/ic_reader_shape_select.svg', attributeBean: AnnotAttributeBean(color: Colors.transparent)), AnnotBean( annotType: AnnotationType.freetext, normalImagePath: 'assets/images/ic_reader_freetext.svg', selectImagePath: 'assets/images/ic_reader_freetext_select.svg', attributeBean: AnnotAttributeBean(color: Colors.transparent)), AnnotBean( annotType: AnnotationType.signature, normalImagePath: 'assets/images/ic_reader_signature.svg', selectImagePath: 'assets/images/ic_reader_signature_select.svg', attributeBean: AnnotAttributeBean(color: Colors.transparent)), AnnotBean( annotType: AnnotationType.stamp, normalImagePath: 'assets/images/ic_reader_stamp.svg', selectImagePath: 'assets/images/ic_reader_stamp_select.svg', attributeBean: AnnotAttributeBean(color: Colors.transparent)), ]; @override void initState() { super.initState(); initAnnotAttr(); setReaderViewContextMenuHelperListener((annotBean) { _attributeOptionsModalBottomSheet(context, annotBean, (AnnotAttributeBean bean) { modifyAnnotationAttribute( annotationType: annotBean.annotType, bean: bean); }, () { dismissModifyAnnotationAttribute(); }); }); } @override Widget build(BuildContext context) { return annotFunctionMenuListWidget(selectAnnot, (annotBean) { var annot = selectAnnot == annotBean.annotType ? AnnotationType.unknown : annotBean.attributeBean.shapeType; setCPDFReaderViewFocusType(annot); setState(() { selectAnnot = selectAnnot == annotBean.annotType ? AnnotationType.unknown : annotBean.annotType; }); if (selectAnnot == AnnotationType.signature) { showAttributeModalBottomSheet(context, annotBean); } }, (annotBean) { setCPDFReaderViewFocusType(annotBean.attributeBean.shapeType); setState(() { selectAnnot = annotBean.annotType; }); showAttributeModalBottomSheet(context, annotBean); }); } Widget annotFunctionMenuListWidget( AnnotationType selectAnnotType, Function(AnnotBean annotBean) onTap, Function(AnnotBean annotBean) onLongPress) { return Container( color: const Color(0xFFEFF4FD), height: 60, alignment: Alignment.centerLeft, child: ListView.builder( itemCount: annotFunList.length, scrollDirection: Axis.horizontal, primary: true, shrinkWrap: true, itemBuilder: (context, index) { AnnotBean bean = annotFunList[index]; return Container( width: 60, padding: const EdgeInsets.all(16), height: 60, color: selectAnnotType == bean.annotType ? const Color(0xFFD5E3FE) : Colors.transparent, child: InkWell( onTap: () { onTap(bean); }, onLongPress: () { onLongPress(bean); }, child: Stack( children: [ Positioned( top: 0, bottom: 0, left: 0, right: 0, child: Container( margin: const EdgeInsets.all(2), color: bean.attributeBean.color, width: double.infinity, height: double.infinity, ), ), Positioned( top: 0, bottom: 0, left: 0, right: 0, child: SvgPicture.asset( selectAnnotType == bean.annotType ? bean.selectImagePath! : bean.normalImagePath!, semanticsLabel: bean.annotType.name, )) ], ), ), ); })); } void showAttributeModalBottomSheet( BuildContext context, AnnotBean annotBean) { _attributeOptionsModalBottomSheet(context, annotBean, (AnnotAttributeBean attributeBean) async { setAnnotAttribute( annotationType: annotBean.annotType, bean: attributeBean); AnnotBean bean = annotFunList .firstWhere((element) => element.annotType == annotBean.annotType); setState(() { bean.attributeBean = attributeBean; }); }, () { setState(() { if (selectAnnot == AnnotationType.signature) { selectAnnot = AnnotationType.unknown; } }); }); } void _attributeOptionsModalBottomSheet(context, AnnotBean annotBean, AnnotAttributeOptionsCallback callback, VoidCallback? closeCallback) { Future close = showModalBottomSheet( context: context, barrierColor: Colors.transparent, isScrollControlled: true, useSafeArea: true, builder: (BuildContext context) { return AnnotAttributeOptionsWidget( attributeOptionsCallback: callback, annotBean: annotBean, ); }); close.then((value) { if (closeCallback != null) { closeCallback(); } }); } void initAnnotAttr() async { AnnotAttributeBean highlight = await getAnnotAttribute(AnnotationType.highlight); AnnotAttributeBean underline = await getAnnotAttribute(AnnotationType.underline); AnnotAttributeBean strikeout = await getAnnotAttribute(AnnotationType.strikeout); AnnotAttributeBean squiggly = await getAnnotAttribute(AnnotationType.squiggly); AnnotAttributeBean ink = await getAnnotAttribute(AnnotationType.ink); AnnotAttributeBean shape = await getAnnotAttribute(AnnotationType.shape); AnnotAttributeBean freeText = await getAnnotAttribute(AnnotationType.freetext); AnnotAttributeBean signature = await getAnnotAttribute(AnnotationType.signature); setState(() { for (var element in annotFunList) { switch (element.annotType) { case AnnotationType.highlight: element.attributeBean = highlight; break; case AnnotationType.underline: element.attributeBean = underline; break; case AnnotationType.strikeout: element.attributeBean = strikeout; break; case AnnotationType.squiggly: element.attributeBean = squiggly; break; case AnnotationType.unknown: break; case AnnotationType.ink: element.attributeBean = ink; break; case AnnotationType.shape: element.attributeBean = shape; break; case AnnotationType.freetext: element.attributeBean = freeText; break; case AnnotationType.signature: element.attributeBean = signature; break; default: break; } } }); } }