|
@@ -0,0 +1,189 @@
|
|
|
+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_color_options_widget.dart';
|
|
|
+import 'package:kmpdfkit_demo/widgets/models/annot_attribute_bean.dart';
|
|
|
+import 'package:kmpdfkit_demo/widgets/models/annot_bean.dart';
|
|
|
+
|
|
|
+class PDFButtonAnnotFunWidget extends StatefulWidget {
|
|
|
+ const PDFButtonAnnotFunWidget({Key? key}) : super(key: key);
|
|
|
+
|
|
|
+ @override
|
|
|
+ State<PDFButtonAnnotFunWidget> createState() =>
|
|
|
+ _PDFButtonAnnotFunWidgetState();
|
|
|
+}
|
|
|
+
|
|
|
+class _PDFButtonAnnotFunWidgetState extends State<PDFButtonAnnotFunWidget> {
|
|
|
+ AnnotType selectAnnot = AnnotType.highlight;
|
|
|
+
|
|
|
+ var annotFunList = [
|
|
|
+ AnnotBean(
|
|
|
+ annotType: AnnotType.highlight,
|
|
|
+ normalImagePath: 'assets/images/ic_reader_highlight.svg',
|
|
|
+ selectImagePath: 'assets/images/ic_reader_highlight_select.svg',
|
|
|
+ annotColor: Colors.red.value,
|
|
|
+ annotColorAlpha: 255),
|
|
|
+ AnnotBean(
|
|
|
+ annotType: AnnotType.underline,
|
|
|
+ normalImagePath: 'assets/images/ic_reader_underline.svg',
|
|
|
+ selectImagePath: 'assets/images/ic_reader_underline_select.svg',
|
|
|
+ annotColor: Colors.blue.value,
|
|
|
+ annotColorAlpha: 255),
|
|
|
+ AnnotBean(
|
|
|
+ annotType: AnnotType.strikeout,
|
|
|
+ normalImagePath: 'assets/images/ic_reader_strikethrough.svg',
|
|
|
+ selectImagePath: 'assets/images/ic_reader_strikethrough_select.svg',
|
|
|
+ annotColor: Colors.green.value,
|
|
|
+ annotColorAlpha: 255),
|
|
|
+ AnnotBean(
|
|
|
+ annotType: AnnotType.squiggly,
|
|
|
+ normalImagePath: 'assets/images/ic_reader_squiggly_underline.svg',
|
|
|
+ selectImagePath:
|
|
|
+ 'assets/images/ic_reader_squiggly_underline_select.svg',
|
|
|
+ annotColor: Colors.pink.value,
|
|
|
+ annotColorAlpha: 255),
|
|
|
+ ];
|
|
|
+
|
|
|
+ @override
|
|
|
+ void initState() {
|
|
|
+ super.initState();
|
|
|
+ initAnnotAttr();
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ Widget build(BuildContext context) {
|
|
|
+ return annotList(selectAnnot, (annotBean) {
|
|
|
+ selectAnnotType(annotBean.annotType);
|
|
|
+ }, (annotBean) {
|
|
|
+ selectAnnotType(annotBean.annotType);
|
|
|
+ _showColorOptionsModalBottomSheet(context, annotBean);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ void selectAnnotType(AnnotType type) {
|
|
|
+ setState(() {
|
|
|
+ selectAnnot = type;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ Widget annotList(
|
|
|
+ AnnotType 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: Color(bean.annotColor),
|
|
|
+ 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 _showColorOptionsModalBottomSheet(context, AnnotBean annotBean) {
|
|
|
+ showModalBottomSheet<int>(
|
|
|
+ context: context,
|
|
|
+ isScrollControlled: false,
|
|
|
+ builder: (BuildContext context) {
|
|
|
+ return AnnotColorOptionsWidget(
|
|
|
+ color: annotBean.annotColor,
|
|
|
+ alpha: annotBean.annotColorAlpha,
|
|
|
+ colorOptionsCallback: (int? color, int? alpha) async {
|
|
|
+ AnnotAttributeBean attr = await setAnnotAttribute(
|
|
|
+ annotType: annotBean.annotType, color: color, alpha: alpha);
|
|
|
+ AnnotBean bean = annotFunList.firstWhere(
|
|
|
+ (element) => element.annotType == annotBean.annotType);
|
|
|
+ setState(() {
|
|
|
+ if (color != null) {
|
|
|
+ bean.annotColor = attr.color;
|
|
|
+ }
|
|
|
+ if (alpha != null) {
|
|
|
+ bean.annotColorAlpha = attr.alpha;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ );
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ void initAnnotAttr() async {
|
|
|
+ AnnotAttributeBean highlight = await getAnnotAttribute(AnnotType.highlight);
|
|
|
+ AnnotAttributeBean underline = await getAnnotAttribute(AnnotType.underline);
|
|
|
+ AnnotAttributeBean strikeout = await getAnnotAttribute(AnnotType.strikeout);
|
|
|
+ AnnotAttributeBean squiggly = await getAnnotAttribute(AnnotType.squiggly);
|
|
|
+ setState(() {
|
|
|
+ annotFunList.forEach((element) {
|
|
|
+ switch (element.annotType) {
|
|
|
+ case AnnotType.highlight:
|
|
|
+ element
|
|
|
+ ..annotColor = highlight.color
|
|
|
+ ..annotColorAlpha = highlight.alpha;
|
|
|
+ break;
|
|
|
+ case AnnotType.underline:
|
|
|
+ element
|
|
|
+ ..annotColor = underline.color
|
|
|
+ ..annotColorAlpha = underline.alpha;
|
|
|
+ break;
|
|
|
+ case AnnotType.strikeout:
|
|
|
+ element
|
|
|
+ ..annotColor = strikeout.color
|
|
|
+ ..annotColorAlpha = strikeout.alpha;
|
|
|
+ break;
|
|
|
+ case AnnotType.squiggly:
|
|
|
+ element
|
|
|
+ ..annotColor = squiggly.color
|
|
|
+ ..annotColorAlpha = squiggly.alpha;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|