123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- 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 {
- AttrStampCallback callback;
- AttrStampWidget({Key? key, required this.callback}) : super(key: key);
- @override
- State<AttrStampWidget> createState() => _AttrStampWidgetState();
- }
- class _AttrStampWidgetState extends State<AttrStampWidget>
- with AutomaticKeepAliveClientMixin, TickerProviderStateMixin {
- List<Tab> tabs = [const Tab(text: 'STANDARD'), const Tab(text: 'CUSTOM')];
- List<TextStampBean> _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<TextStampBean> 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<TextStampBean> customStampList =
- await StampUtil.getCustomTextStampList();
- setState(() {
- _customTextStampList = customStampList;
- });
- }
- }
|