print_page.dart 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/services.dart';
  3. import 'package:lszlgl/base/base_lifecycle_state.dart';
  4. import 'package:lszlgl/page/print/connect_print_page.dart';
  5. import 'package:signature/signature.dart';
  6. import 'package:lszlgl/widget/button.dart';
  7. import '../../service/print_service.dart';
  8. import '../home/home_page.dart';
  9. class PrintPageArgs {
  10. /// 签名数量
  11. int count;
  12. PrintPageArgs({this.count = 1});
  13. @override
  14. String toString() {
  15. return {'count': count}.toString();
  16. }
  17. }
  18. /// 电子签名
  19. class PrintPage extends StatefulWidget {
  20. final PrintPageArgs args;
  21. const PrintPage({
  22. super.key,
  23. required this.args,
  24. });
  25. @override
  26. State<PrintPage> createState() => _PrintPageState();
  27. }
  28. class _PrintPageState extends BaseLifecycleState<PrintPage> {
  29. late int count;
  30. late List<SignatureController> ctrlList;
  31. late PageController pageCtrl;
  32. final previousEnable = false.notifier<bool>();
  33. final nextEnable = false.notifier<bool>();
  34. final submitEnable = false.notifier<bool>();
  35. late List<ServiceModel> serviceList;
  36. @override
  37. void initState() {
  38. super.initState();
  39. serviceList = [
  40. ServiceModel(name: '连接', icon: imgHomeListPzjc, onTap: () => startConnect()),
  41. ServiceModel(name: '打印', icon: imgHomeListZcjy, onTap: () => startPrint()),
  42. ];
  43. }
  44. Future<void> startConnect() async {
  45. var args = ConnectPrintPageArgs(count: 0);
  46. await MyRouter.startConnectPrint(args: args);
  47. }
  48. /// 去打印
  49. Future<void> startPrint() async {
  50. // await PrintService.startBluetoothPair(deviceInfo);
  51. }
  52. @override
  53. void onInit() {
  54. // 创建签名列表
  55. count = widget.args.count;
  56. ctrlList = List.generate(
  57. count,
  58. (index) => SignatureController(
  59. penStrokeWidth: 6,
  60. penColor: Colors.black,
  61. strokeJoin: StrokeJoin.round,
  62. strokeCap: StrokeCap.round,
  63. ),
  64. ).toList();
  65. pageCtrl = PageController();
  66. if (count == 1) {
  67. submitEnable.value = true;
  68. } else {
  69. nextEnable.value = true;
  70. }
  71. }
  72. @override
  73. void onDestroy() {
  74. SystemChrome.setPreferredOrientations([
  75. DeviceOrientation.portraitUp,
  76. DeviceOrientation.portraitDown,
  77. ]);
  78. for (var ctrl in ctrlList) {
  79. ctrl.dispose();
  80. }
  81. }
  82. @override
  83. Widget build(BuildContext context) {
  84. return myScaffold(
  85. child: Column(
  86. children: [
  87. myAppBar(title: '打印二维码'),
  88. const SizedBox(height: 18),
  89. ...List.generate(
  90. serviceList.length,
  91. (index) => buildServiceItem(serviceList[index]),
  92. ).toList(),
  93. ],
  94. ),
  95. );
  96. }
  97. Widget buildServiceItem(ServiceModel service) {
  98. return GestureDetector(
  99. onTap: service.onTap,
  100. child: Container(
  101. margin: const EdgeInsets.only(left: 12, right: 12, bottom: 22),
  102. padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 40),
  103. clipBehavior: Clip.hardEdge,
  104. decoration: BoxDecoration(
  105. borderRadius: const BorderRadius.all(Radius.circular(12)),
  106. boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.1), offset: const Offset(0, 5), blurRadius: 4)],
  107. image: const DecorationImage(image: AssetImage(imgHomeListBg), fit: BoxFit.fill),
  108. ),
  109. child: Row(
  110. children: [
  111. Image.asset(service.icon, height: 64),
  112. const SizedBox(width: 12),
  113. Expanded(
  114. child: Column(
  115. mainAxisSize: MainAxisSize.min,
  116. children: [
  117. Text(
  118. service.name,
  119. textAlign: TextAlign.center,
  120. style: const TextStyle(color: Color(0xFF333333), fontSize: 20, fontWeight: FontWeight.w500),
  121. ),
  122. service.nameEn != null
  123. ? Padding(
  124. padding: const EdgeInsets.only(top: 4),
  125. child: Text(
  126. service.nameEn!,
  127. textAlign: TextAlign.center,
  128. style: const TextStyle(color: Color(0xFF333333), fontSize: 12, fontWeight: FontWeight.w500),
  129. ),
  130. )
  131. : const SizedBox.shrink(),
  132. ],
  133. ),
  134. ),
  135. ],
  136. ),
  137. ),
  138. );
  139. }
  140. }