attr_stamp_widget.dart 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. import 'package:kmpdfkit_demo/widgets/contains.dart';
  4. import 'package:kmpdfkit_demo/widgets/function/attrwidget/stamp/attr_custom_stamp_edit_widget.dart';
  5. import 'package:kmpdfkit_demo/widgets/models/standard_stamp_bean.dart';
  6. import 'package:kmpdfkit_demo/widgets/models/text_stamp_bean.dart';
  7. import 'package:kmpdfkit_demo/widgets/util/stamp_util.dart';
  8. /// attr_stamp_widget.dart
  9. ///
  10. /// Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
  11. ///
  12. /// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  13. /// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  14. /// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  15. /// This notice may not be removed from this file.
  16. var standardStampList = [
  17. StandardStampBean(StandardStamp.approved, 'ic_stamp_app_roved.png'),
  18. StandardStampBean(StandardStamp.notapproved, 'ic_stamp_not_app_roved.png'),
  19. StandardStampBean(StandardStamp.draft, 'ic_stamp_draft.png'),
  20. StandardStampBean(StandardStamp.FINAL, 'ic_stamp_final.png'),
  21. StandardStampBean(StandardStamp.completed, 'ic_stamp_complete.png'),
  22. StandardStampBean(StandardStamp.confidential, 'ic_stamp_confidential.png'),
  23. StandardStampBean(
  24. StandardStamp.forpublicrelease, 'ic_stamp_for_public_release.png'),
  25. StandardStampBean(
  26. StandardStamp.notforpublicrelease, 'ic_stamp_not_for_public_release.png'),
  27. StandardStampBean(StandardStamp.forcomment, 'ic_stamp_for_comment.png'),
  28. StandardStampBean(StandardStamp.VOID, 'ic_stamp_void.png'),
  29. StandardStampBean(
  30. StandardStamp.preliminaryresults, 'ic_stamp_preliminary_results.png'),
  31. StandardStampBean(
  32. StandardStamp.informationonly, 'ic_stamp_information_only.png'),
  33. StandardStampBean(StandardStamp.witness, 'ic_stamp_witness.png'),
  34. StandardStampBean(StandardStamp.initialhere, 'ic_stamp_initial_here.png'),
  35. StandardStampBean(StandardStamp.signhere, 'ic_stamp_sign_here.png'),
  36. StandardStampBean(StandardStamp.revised, 'ic_stamp_revised.png'),
  37. StandardStampBean(StandardStamp.accepted, 'ic_stamp_accepted.png'),
  38. StandardStampBean(StandardStamp.rejected, 'ic_stamp_rejected.png'),
  39. StandardStampBean(
  40. StandardStamp.privateaccepted, 'ic_stamp_private_mark_1.png'),
  41. StandardStampBean(
  42. StandardStamp.privaterejected, 'ic_stamp_private_mark_2.png'),
  43. StandardStampBean(
  44. StandardStamp.privateradiomark, 'ic_stamp_private_mark_3.png'),
  45. ];
  46. typedef AttrStampCallback = Function(
  47. String? standardStampName, TextStampBean? textStampBean);
  48. class AttrStampWidget extends StatefulWidget {
  49. AttrStampCallback callback;
  50. AttrStampWidget({Key? key, required this.callback}) : super(key: key);
  51. @override
  52. State<AttrStampWidget> createState() => _AttrStampWidgetState();
  53. }
  54. class _AttrStampWidgetState extends State<AttrStampWidget>
  55. with AutomaticKeepAliveClientMixin, TickerProviderStateMixin {
  56. List<Tab> tabs = [const Tab(text: 'STANDARD'), const Tab(text: 'CUSTOM')];
  57. List<TextStampBean> _customTextStampList = [];
  58. late TabController _tabController;
  59. bool _isEditMode = false;
  60. int _selectIndex = 0;
  61. @override
  62. void initState() {
  63. super.initState();
  64. _tabController = TabController(length: tabs.length, vsync: this);
  65. _tabController.addListener(() {
  66. setState(() {
  67. _selectIndex = _tabController.index;
  68. });
  69. });
  70. _refreshCustomStampList();
  71. }
  72. @override
  73. Widget build(BuildContext context) {
  74. return Scaffold(
  75. appBar: AppBar(
  76. actions: [
  77. if (_selectIndex == 1) ...{
  78. IconButton(
  79. onPressed: () async {
  80. if (_isEditMode) {
  81. List<TextStampBean> selectList = _customTextStampList.where((element) => element.select).toList();
  82. await StampUtil.deleteTextStamp(selectList);
  83. _refreshCustomStampList();
  84. }
  85. setState(() {
  86. _isEditMode = !_isEditMode;
  87. });
  88. },
  89. icon: Icon(_isEditMode ? Icons.delete : Icons.edit))
  90. }
  91. ],
  92. ),
  93. body: Column(
  94. children: [
  95. TabBar(
  96. tabs: tabs,
  97. controller: _tabController,
  98. indicatorWeight: 2.0,
  99. unselectedLabelColor: Colors.grey,
  100. labelColor: Colors.blue,
  101. ),
  102. Expanded(
  103. child: TabBarView(
  104. controller: _tabController,
  105. children: [_standardStampList(), _customStampWidgetList()],
  106. ))
  107. ],
  108. ));
  109. }
  110. @override
  111. bool get wantKeepAlive => true;
  112. Widget _standardStampList() {
  113. return GridView.builder(
  114. itemCount: standardStampList.length,
  115. gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
  116. crossAxisCount: 2, childAspectRatio: 2.2),
  117. itemBuilder: (BuildContext context, int index) {
  118. StandardStampBean bean = standardStampList[index];
  119. return InkWell(
  120. child: Padding(
  121. padding: const EdgeInsets.all(16),
  122. child: Image.asset(bean.getImagePath()),
  123. ),
  124. onTap: () {
  125. widget.callback(bean.standardStamp.name, null);
  126. },
  127. );
  128. });
  129. }
  130. Widget _customStampWidgetList() {
  131. return Stack(
  132. children: [
  133. GridView.builder(
  134. itemCount: _customTextStampList.length,
  135. gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
  136. crossAxisCount: 2, childAspectRatio: 2.2),
  137. itemBuilder: (BuildContext context, int index) {
  138. TextStampBean bean = _customTextStampList[index];
  139. return Stack(
  140. children: [
  141. InkWell(
  142. child: Padding(
  143. padding: const EdgeInsets.all(16),
  144. child: bean.previewImagePath?.isNotEmpty == true
  145. ? Image.file(File(bean.previewImagePath!))
  146. : Container(),
  147. ),
  148. onTap: () {
  149. widget.callback(null, _customTextStampList[index]);
  150. },
  151. ),
  152. if (_isEditMode) ...{
  153. Positioned(
  154. top: 0,
  155. right: 0,
  156. child: Checkbox(
  157. value: bean.select,
  158. onChanged: (value) {
  159. setState(() {
  160. bean.select = value!;
  161. });
  162. }))
  163. }
  164. ],
  165. );
  166. }),
  167. Positioned(
  168. bottom: 20,
  169. right: 20,
  170. child: FloatingActionButton(
  171. onPressed: () async {
  172. await Navigator.push(context,
  173. MaterialPageRoute(builder: (BuildContext context) {
  174. return const AttrCustomStampEditWidget();
  175. }));
  176. _refreshCustomStampList();
  177. },
  178. child: const Icon(Icons.add),
  179. ))
  180. ],
  181. );
  182. }
  183. void _refreshCustomStampList() async {
  184. List<TextStampBean> customStampList =
  185. await StampUtil.getCustomTextStampList();
  186. setState(() {
  187. _customTextStampList = customStampList;
  188. });
  189. }
  190. }