attr_free_text_widget.dart 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import 'package:flutter/material.dart';
  2. import 'package:kmpdfkit_demo/widgets/constains.dart';
  3. import 'package:kmpdfkit_demo/widgets/models/annot_attribute_bean.dart';
  4. import 'attr_color_list_widget.dart';
  5. import 'base_slider_widget.dart';
  6. typedef AttrFreeTextCallback = Function(AnnotAttributeBean);
  7. /// attr_free_text_widget.dart
  8. ///
  9. /// Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
  10. ///
  11. /// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  12. /// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  13. /// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  14. /// This notice may not be removed from this file.
  15. class AttrFreeTextWidget extends StatefulWidget {
  16. AnnotAttributeBean bean;
  17. AttrFreeTextCallback callback;
  18. AttrFreeTextWidget({Key? key, required this.bean, required this.callback})
  19. : super(key: key);
  20. @override
  21. State<AttrFreeTextWidget> createState() => _AttrFreeTextWidgetState();
  22. }
  23. class _AttrFreeTextWidgetState extends State<AttrFreeTextWidget> {
  24. bool _isFontWidget = true;
  25. bool isBold = false;
  26. @override
  27. Widget build(BuildContext context) {
  28. return Column(
  29. children: [
  30. Row(
  31. children: [
  32. Expanded(
  33. child: TextButton(
  34. onPressed: () {
  35. setState(() {
  36. _isFontWidget = true;
  37. });
  38. },
  39. child: Text(
  40. 'FONT',
  41. style: TextStyle(
  42. color: _isFontWidget ? Colors.blue : Colors.grey,
  43. fontWeight: _isFontWidget
  44. ? FontWeight.bold
  45. : FontWeight.normal),
  46. ))),
  47. Expanded(
  48. child: TextButton(
  49. onPressed: () {
  50. setState(() {
  51. _isFontWidget = false;
  52. });
  53. },
  54. child: Text('STYLE',
  55. style: TextStyle(
  56. color: !_isFontWidget ? Colors.blue : Colors.grey,
  57. fontWeight: !_isFontWidget
  58. ? FontWeight.bold
  59. : FontWeight.normal))))
  60. ],
  61. ),
  62. _isFontWidget ? _fontWidget() : _styleWidget()
  63. ],
  64. );
  65. }
  66. Widget _fontWidget() {
  67. return Column(
  68. key: const ValueKey('free_text_font'),
  69. children: [
  70. Row(
  71. children: [
  72. TextButton(
  73. onPressed: () {
  74. setState(() {
  75. widget.bean.fontBold = !widget.bean.fontBold;
  76. widget.callback(widget.bean);
  77. });
  78. },
  79. child: Text('B',
  80. style: TextStyle(
  81. fontWeight: FontWeight.bold,
  82. fontSize: 16,
  83. color:
  84. widget.bean.fontBold ? Colors.blue : Colors.grey))),
  85. TextButton(
  86. onPressed: () {
  87. setState(() {
  88. widget.bean.fontItalic = !widget.bean.fontItalic;
  89. widget.callback(widget.bean);
  90. });
  91. },
  92. child: Text('I',
  93. style: TextStyle(
  94. fontWeight: FontWeight.bold,
  95. fontSize: 16,
  96. fontStyle: FontStyle.italic,
  97. color: widget.bean.fontItalic
  98. ? Colors.blue
  99. : Colors.grey)))
  100. ],
  101. ),
  102. ListView(
  103. primary: true,
  104. shrinkWrap: true,
  105. children: [
  106. for (var value in FontType.values) ...{
  107. ListTile(
  108. title: Text(value.name),
  109. trailing: widget.bean.fontType == value
  110. ? const Icon(Icons.check)
  111. : null,
  112. onTap: () {
  113. setState(() {
  114. widget.bean.fontType = value;
  115. widget.callback(widget.bean);
  116. });
  117. },
  118. ),
  119. const Divider(color: Colors.grey, height: 1)
  120. }
  121. ],
  122. )
  123. ],
  124. );
  125. }
  126. Widget _styleWidget() {
  127. return Column(
  128. key: const ValueKey('free_text_style'),
  129. children: [
  130. ColorListWidget(
  131. color: widget.bean.textColor,
  132. colorOptionsCallback: (textColor) {
  133. widget.bean.textColor = textColor;
  134. widget.callback(widget.bean);
  135. }),
  136. colorAlphaWidget(
  137. currentAlphaValue: widget.bean.textColorAlpha,
  138. alphaOptionsCallback: (textColorAlpha) {
  139. widget.bean.textColorAlpha = textColorAlpha.round();
  140. widget.callback(widget.bean);
  141. }),
  142. BaseSliderWidget(
  143. sliderCurrentValue: widget.bean.fontSize.toDouble(),
  144. sliderMinValue: 1,
  145. sliderMaxValue: 100,
  146. icon: Icons.format_size,
  147. valueShowType: ValueShowType.sourceValue,
  148. sliderValueCallback: (fontSize) {
  149. widget.bean.fontSize = fontSize.round();
  150. widget.callback(widget.bean);
  151. })
  152. ],
  153. );
  154. }
  155. }