| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:lszlgl/base/base_lifecycle_state.dart';
- import 'package:lszlgl/page/print/connect_print_page.dart';
- import 'package:signature/signature.dart';
- import 'package:lszlgl/widget/button.dart';
- import '../../service/print_service.dart';
- import '../home/home_page.dart';
- class PrintPageArgs {
- /// 签名数量
- int count;
- PrintPageArgs({this.count = 1});
- @override
- String toString() {
- return {'count': count}.toString();
- }
- }
- /// 电子签名
- class PrintPage extends StatefulWidget {
- final PrintPageArgs args;
- const PrintPage({
- super.key,
- required this.args,
- });
- @override
- State<PrintPage> createState() => _PrintPageState();
- }
- class _PrintPageState extends BaseLifecycleState<PrintPage> {
- late int count;
- late List<SignatureController> ctrlList;
- late PageController pageCtrl;
- final previousEnable = false.notifier<bool>();
- final nextEnable = false.notifier<bool>();
- final submitEnable = false.notifier<bool>();
- late List<ServiceModel> serviceList;
- @override
- void initState() {
- super.initState();
- serviceList = [
- ServiceModel(name: '连接', icon: imgHomeListPzjc, onTap: () => startConnect()),
- ServiceModel(name: '打印', icon: imgHomeListZcjy, onTap: () => startPrint()),
- ];
- }
- Future<void> startConnect() async {
- var args = ConnectPrintPageArgs(count: 0);
- await MyRouter.startConnectPrint(args: args);
- }
- /// 去打印
- Future<void> startPrint() async {
- // await PrintService.startBluetoothPair(deviceInfo);
- }
- @override
- void onInit() {
- // 创建签名列表
- count = widget.args.count;
- ctrlList = List.generate(
- count,
- (index) => SignatureController(
- penStrokeWidth: 6,
- penColor: Colors.black,
- strokeJoin: StrokeJoin.round,
- strokeCap: StrokeCap.round,
- ),
- ).toList();
- pageCtrl = PageController();
- if (count == 1) {
- submitEnable.value = true;
- } else {
- nextEnable.value = true;
- }
- }
- @override
- void onDestroy() {
- SystemChrome.setPreferredOrientations([
- DeviceOrientation.portraitUp,
- DeviceOrientation.portraitDown,
- ]);
- for (var ctrl in ctrlList) {
- ctrl.dispose();
- }
- }
- @override
- Widget build(BuildContext context) {
- return myScaffold(
- child: Column(
- children: [
- myAppBar(title: '打印二维码'),
- const SizedBox(height: 18),
- ...List.generate(
- serviceList.length,
- (index) => buildServiceItem(serviceList[index]),
- ).toList(),
- ],
- ),
- );
- }
- Widget buildServiceItem(ServiceModel service) {
- return GestureDetector(
- onTap: service.onTap,
- child: Container(
- margin: const EdgeInsets.only(left: 12, right: 12, bottom: 22),
- padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 40),
- clipBehavior: Clip.hardEdge,
- decoration: BoxDecoration(
- borderRadius: const BorderRadius.all(Radius.circular(12)),
- boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.1), offset: const Offset(0, 5), blurRadius: 4)],
- image: const DecorationImage(image: AssetImage(imgHomeListBg), fit: BoxFit.fill),
- ),
- child: Row(
- children: [
- Image.asset(service.icon, height: 64),
- const SizedBox(width: 12),
- Expanded(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Text(
- service.name,
- textAlign: TextAlign.center,
- style: const TextStyle(color: Color(0xFF333333), fontSize: 20, fontWeight: FontWeight.w500),
- ),
- service.nameEn != null
- ? Padding(
- padding: const EdgeInsets.only(top: 4),
- child: Text(
- service.nameEn!,
- textAlign: TextAlign.center,
- style: const TextStyle(color: Color(0xFF333333), fontSize: 12, fontWeight: FontWeight.w500),
- ),
- )
- : const SizedBox.shrink(),
- ],
- ),
- ),
- ],
- ),
- ),
- );
- }
- }
|