plan_dish_qrcode_page.dart
9.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import 'dart:io';
import 'dart:typed_data';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:one_key/provider/plan_dish_provider.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/utils/screen_util.dart';
import 'package:one_key/utils/utils.dart';
import 'package:one_key/widgets/loading.dart';
import 'package:one_key/widgets/round_button.dart';
import 'package:one_key/widgets/system_app_bar.dart';
import 'package:one_key/widgets/v_empty_view.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';
import 'dart:ui' as ui;
/**
*
*
* 套餐排菜分享二维码
*
*
*/
class PlanDishQrcodePage extends StatefulWidget {
final String qrcode;
const PlanDishQrcodePage({super.key, required this.qrcode});
@override
State<PlanDishQrcodePage> createState() => _PlanDishQrcodePageState();
}
class _PlanDishQrcodePageState extends State<PlanDishQrcodePage> {
final GlobalKey globalKey = GlobalKey();
late PlanDishProvider planDishProvider;
// _createPayQrcode() {
// financeProvider!.createPayQrcode(context);
// }
/// 截图
Future<Uint8List?> _capturePng(
GlobalKey globalKey,
// {
// double pixelRatio = 2.0, //截屏的图片与原图的比例
// }
) async {
try {
RenderRepaintBoundary boundary =
globalKey.currentContext?.findRenderObject() as RenderRepaintBoundary;
double dpr = ui.window.devicePixelRatio; // 获取当前设备的像素比
var image = await boundary.toImage(pixelRatio: dpr);
ByteData? byteData =
await image.toByteData(format: ui.ImageByteFormat.png);
Uint8List? pngBytes = byteData?.buffer.asUint8List();
return pngBytes;
} catch (e) {
print(e);
}
return null;
}
@override
Widget build(BuildContext context) {
planDishProvider = Provider.of<PlanDishProvider>(context, listen: true);
return Scaffold(
appBar: SystemAppBar('店铺套餐分享'),
backgroundColor: MyColours.color_ffffff,
body: Column(
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
VEmptyView(100),
//二维码图片
//
RepaintBoundary(
key: globalKey,
child: Column(
children: [
Container(
margin: EdgeInsets.symmetric(horizontal: w(57)),
padding: EdgeInsets.symmetric(
horizontal: w(25), vertical: w(35)),
color: MyColours.color_438E93,
child: Column(
children: [
Text(
'微信扫码查看店铺套餐',
style: TextStyle(
color: MyColours.color_ffffff,
fontSize: font(16),
fontWeight: FontWeight.bold),
),
VEmptyView(20),
Container(
padding: EdgeInsets.symmetric(
horizontal: w(21), vertical: w(16)),
color: MyColours.color_ffffff,
child: Column(
children: [
CachedNetworkImage(
imageUrl:
widget.qrcode ?? ''),
// VEmptyView(28),
Text(
'${Provider.of<UserModel>(context).user!.sellername}',
maxLines: 3,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: MyColours.color_000000,
fontSize: font(14)),
),
// VEmptyView(28),
// Text(
// '消费金:¥${widget.data.amount}',
// maxLines: 3,
// overflow: TextOverflow.ellipsis,
// style: TextStyle(
// color: MyColours.color_000000,
// fontSize: font(14)),
// ),
],
))
],
),
),
// Container(
// margin: EdgeInsets.symmetric(horizontal: w(57)),
// padding: EdgeInsets.symmetric(
// horizontal: w(25), vertical: w(11)),
// decoration: BoxDecoration(
// color: MyColours.color_ffffff,
// border: Border.all(
// color: MyColours.color_09BB07,
// width: w(2))),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.center,
// children: [
// Image.asset(
// Utils.getImgPath('vector'),
// width: w(37),
// ),
// HEmptyView(12),
// Text(
// '微信支付',
// style: TextStyle(
// color: MyColours.color_515151,
// fontSize: font(28)),
// )
// ],
// )),
],
)),
VEmptyView(160),
// Padding(
// padding: EdgeInsets.symmetric(horizontal: w(16)),
// child: Text(
// '提示:',
// textAlign: TextAlign.left,
// style: TextStyle(
// fontSize: w(16),
// height: 1.5,
// fontWeight: FontWeight.bold,
// color: MyColours.color_000000),
// )),
// Padding(
// padding: EdgeInsets.symmetric(horizontal: w(16)),
// child: Text(
// '请将收款码出示给顾客,顾客扫码支付时可以自动识别拥有的代金券,并自动在餐厅设定的规则下使用。',
// textAlign: TextAlign.left,
// style: TextStyle(
// fontSize: w(14),
// height: 1.5,
// color: MyColours.color_000000),
// ))
],
),
),
),
Container(
padding: EdgeInsets.symmetric(vertical: w(13), horizontal: w(79)),
child: RoundButton(
text: '保存二维码图片',
height: w(43),
radius: r(5),
gradientStart: MyColours.color_ffffff,
gradientEnd: MyColours.color_ffffff,
borderColor: MyColours.color_438E93,
textColor: MyColours.color_438E93,
isBold: true,
fontSize: 32,
onPressed: () {
Utils.getPickPermission(context, () async {
//获取截屏图像
//添加到图片数组中
Loading.showLoading(
context,
);
Uint8List? value = await _capturePng(globalKey);
if (value != null) {
print(value);
final result = await ImageGallerySaver.saveImage(value,
quality: 100);
if (result != null) {
Utils.showToast("保存成功");
} else {
print('error');
Utils.showToast("保存失败");
// toast("");
}
Loading.hideLoading(context);
// setState(() {});
}
}, Platform.isIOS ? Permission.photos : Permission.storage);
},
),
)
],
));
}
}