import 'dart:io'; import 'package:flutter/material.dart'; import 'package:kmpdfkit_demo/widgets/contains.dart'; import 'package:kmpdfkit_demo/widgets/function/attrwidget/stamp/attr_custom_stamp_edit_widget.dart'; import 'package:kmpdfkit_demo/widgets/models/standard_stamp_bean.dart'; import 'package:kmpdfkit_demo/widgets/models/text_stamp_bean.dart'; import 'package:kmpdfkit_demo/widgets/util/stamp_util.dart'; /// attr_stamp_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. var standardStampList = [ StandardStampBean(StandardStamp.approved, 'ic_stamp_app_roved.png'), StandardStampBean(StandardStamp.notapproved, 'ic_stamp_not_app_roved.png'), StandardStampBean(StandardStamp.draft, 'ic_stamp_draft.png'), StandardStampBean(StandardStamp.FINAL, 'ic_stamp_final.png'), StandardStampBean(StandardStamp.completed, 'ic_stamp_complete.png'), StandardStampBean(StandardStamp.confidential, 'ic_stamp_confidential.png'), StandardStampBean( StandardStamp.forpublicrelease, 'ic_stamp_for_public_release.png'), StandardStampBean( StandardStamp.notforpublicrelease, 'ic_stamp_not_for_public_release.png'), StandardStampBean(StandardStamp.forcomment, 'ic_stamp_for_comment.png'), StandardStampBean(StandardStamp.VOID, 'ic_stamp_void.png'), StandardStampBean( StandardStamp.preliminaryresults, 'ic_stamp_preliminary_results.png'), StandardStampBean( StandardStamp.informationonly, 'ic_stamp_information_only.png'), StandardStampBean(StandardStamp.witness, 'ic_stamp_witness.png'), StandardStampBean(StandardStamp.initialhere, 'ic_stamp_initial_here.png'), StandardStampBean(StandardStamp.signhere, 'ic_stamp_sign_here.png'), StandardStampBean(StandardStamp.revised, 'ic_stamp_revised.png'), StandardStampBean(StandardStamp.accepted, 'ic_stamp_accepted.png'), StandardStampBean(StandardStamp.rejected, 'ic_stamp_rejected.png'), StandardStampBean( StandardStamp.privateaccepted, 'ic_stamp_private_mark_1.png'), StandardStampBean( StandardStamp.privaterejected, 'ic_stamp_private_mark_2.png'), StandardStampBean( StandardStamp.privateradiomark, 'ic_stamp_private_mark_3.png'), ]; typedef AttrStampCallback = Function( String? standardStampName, TextStampBean? textStampBean); class AttrStampWidget extends StatefulWidget { final AttrStampCallback callback; const AttrStampWidget({Key? key, required this.callback}) : super(key: key); @override State createState() => _AttrStampWidgetState(); } class _AttrStampWidgetState extends State with AutomaticKeepAliveClientMixin, TickerProviderStateMixin { List tabs = [const Tab(text: 'STANDARD'), const Tab(text: 'CUSTOM')]; List _customTextStampList = []; late TabController _tabController; bool _isEditMode = false; int _selectIndex = 0; @override void initState() { super.initState(); _tabController = TabController(length: tabs.length, vsync: this); _tabController.addListener(() { setState(() { _selectIndex = _tabController.index; }); }); _refreshCustomStampList(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( actions: [ if (_selectIndex == 1) ...{ IconButton( onPressed: () async { if (_isEditMode) { List selectList = _customTextStampList.where((element) => element.select).toList(); await StampUtil.deleteTextStamp(selectList); _refreshCustomStampList(); } setState(() { _isEditMode = !_isEditMode; }); }, icon: Icon(_isEditMode ? Icons.delete : Icons.edit)) } ], ), body: Column( children: [ TabBar( tabs: tabs, controller: _tabController, indicatorWeight: 2.0, unselectedLabelColor: Colors.grey, labelColor: Colors.blue, ), Expanded( child: TabBarView( controller: _tabController, children: [_standardStampList(), _customStampWidgetList()], )) ], )); } @override bool get wantKeepAlive => true; Widget _standardStampList() { return GridView.builder( itemCount: standardStampList.length, gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 2, childAspectRatio: 2.2), itemBuilder: (BuildContext context, int index) { StandardStampBean bean = standardStampList[index]; return InkWell( child: Padding( padding: const EdgeInsets.all(16), child: Image.asset(bean.getImagePath()), ), onTap: () { widget.callback(bean.standardStamp.name, null); }, ); }); } Widget _customStampWidgetList() { return Stack( children: [ GridView.builder( itemCount: _customTextStampList.length, gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 2, childAspectRatio: 2.2), itemBuilder: (BuildContext context, int index) { TextStampBean bean = _customTextStampList[index]; return Stack( children: [ InkWell( child: Padding( padding: const EdgeInsets.all(16), child: bean.previewImagePath?.isNotEmpty == true ? Image.file(File(bean.previewImagePath!)) : Container(), ), onTap: () { widget.callback(null, _customTextStampList[index]); }, ), if (_isEditMode) ...{ Positioned( top: 0, right: 0, child: Checkbox( value: bean.select, onChanged: (value) { setState(() { bean.select = value!; }); })) } ], ); }), Positioned( bottom: 20, right: 20, child: FloatingActionButton( onPressed: () async { await Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) { return const AttrCustomStampEditWidget(); })); _refreshCustomStampList(); }, child: const Icon(Icons.add), )) ], ); } void _refreshCustomStampList() async { List customStampList = await StampUtil.getCustomTextStampList(); setState(() { _customTextStampList = customStampList; }); } }