Commit 88f32d67cfa12231c9844ef03fe2707052388ae0

Authored by wdn127929
1 parent 544d47cb

生成预览and微信分享

@@ -32,6 +32,7 @@ class MenuModel { @@ -32,6 +32,7 @@ class MenuModel {
32 order = json['order']; 32 order = json['order'];
33 status = json['status']; 33 status = json['status'];
34 classType = json['class_type']; 34 classType = json['class_type'];
  35 + // allSum = json['allSum'] ?? 0;
35 if (json['cookbooklist'] != null) { 36 if (json['cookbooklist'] != null) {
36 cookbooklist = []; 37 cookbooklist = [];
37 json['cookbooklist'][0].forEach((v) { 38 json['cookbooklist'][0].forEach((v) {
@@ -48,6 +49,7 @@ class MenuModel { @@ -48,6 +49,7 @@ class MenuModel {
48 order = json['order']; 49 order = json['order'];
49 status = json['status']; 50 status = json['status'];
50 classType = json['class_type']; 51 classType = json['class_type'];
  52 + allSum = json['allSum'] ?? 0;
51 if (json['cookbooklist'] != null) { 53 if (json['cookbooklist'] != null) {
52 cookbooklist = []; 54 cookbooklist = [];
53 json['cookbooklist'].forEach((v) { 55 json['cookbooklist'].forEach((v) {
@@ -65,6 +67,7 @@ class MenuModel { @@ -65,6 +67,7 @@ class MenuModel {
65 data['order'] = this.order; 67 data['order'] = this.order;
66 data['status'] = this.status; 68 data['status'] = this.status;
67 data['class_type'] = this.classType; 69 data['class_type'] = this.classType;
  70 + data['allSum'] = this.allSum;
68 if (this.cookbooklist != null) { 71 if (this.cookbooklist != null) {
69 data['cookbooklist'] = this.cookbooklist.map((v) => v.toJson()).toList(); 72 data['cookbooklist'] = this.cookbooklist.map((v) => v.toJson()).toList();
70 } 73 }
@@ -104,7 +107,7 @@ class MenuSunModel { @@ -104,7 +107,7 @@ class MenuSunModel {
104 List<MenuModel> cookList; 107 List<MenuModel> cookList;
105 108
106 int amount; //菜品数量 109 int amount; //菜品数量
107 - 110 +
108 TextEditingController amountC = TextEditingController(); 111 TextEditingController amountC = TextEditingController();
109 int moreSum = 0; //排菜编辑页展示选中总数 112 int moreSum = 0; //排菜编辑页展示选中总数
110 113
@@ -177,6 +180,43 @@ class MenuSunModel { @@ -177,6 +180,43 @@ class MenuSunModel {
177 } 180 }
178 } 181 }
179 182
  183 + MenuSunModel.fromJson3(Map<String, dynamic> json) {
  184 + id = json['id'];
  185 + sellerid = json['sellerid'];
  186 + mid = json['mid'];
  187 + lid = json['lid'];
  188 + unit = json['unit'];
  189 + name = json['name'];
  190 + price = json['price'];
  191 + member_price = json['member_price'];
  192 + first_name = json['first_name'];
  193 + search_code = json['search_code'];
  194 + channel = json['channel'];
  195 + dishesvideo = json['dishesvideo'];
  196 + dishesgif = json['dishesgif'];
  197 + status = json['status'];
  198 + setup = json['setup'];
  199 + give = json['give'];
  200 + clear_num = json['clear_num'];
  201 + record_num = json['record_num'];
  202 + image = json['image'];
  203 + is_weigh = json['is_weigh'];
  204 + desc = json['desc'];
  205 + order_o = json['order_o'];
  206 + cdate = json['cdate'];
  207 + spec = json['spec'];
  208 + isSpec = json['isSpec'];
  209 + practice = json['practice'];
  210 + amount = 0;
  211 + amountC.text = '0';
  212 + if (json['cookList'] != null) {
  213 + cookList = [];
  214 + json['cookList'].forEach((v) {
  215 + cookList.add(v);
  216 + });
  217 + }
  218 + }
  219 +
180 MenuSunModel.fromJson2(Map<String, dynamic> json) { 220 MenuSunModel.fromJson2(Map<String, dynamic> json) {
181 id = json['id']; 221 id = json['id'];
182 sellerid = json['sellerid']; 222 sellerid = json['sellerid'];
@@ -52,6 +52,9 @@ class _OrderAdvanceEidtPageState extends State<OrderAdvanceEidtPage> { @@ -52,6 +52,9 @@ class _OrderAdvanceEidtPageState extends State<OrderAdvanceEidtPage> {
52 TextEditingController planDishC = TextEditingController(); //排菜价 52 TextEditingController planDishC = TextEditingController(); //排菜价
53 List<MenuSunModel> selectMenu = []; 53 List<MenuSunModel> selectMenu = [];
54 54
  55 + String planDishName;
  56 + String planDishRemark;
  57 +
55 @override 58 @override
56 void initState() { 59 void initState() {
57 super.initState(); 60 super.initState();
@@ -78,17 +81,19 @@ class _OrderAdvanceEidtPageState extends State<OrderAdvanceEidtPage> { @@ -78,17 +81,19 @@ class _OrderAdvanceEidtPageState extends State<OrderAdvanceEidtPage> {
78 List<SunListPlan> storeList = _planDishProvider.storeListTemp; 81 List<SunListPlan> storeList = _planDishProvider.storeListTemp;
79 82
80 storeList.forEach((element) { 83 storeList.forEach((element) {
81 - MenuSunModel menuSunModel = MenuSunModel();  
82 - menuSunModel.id = element.id;  
83 - menuSunModel.name = element.pname;  
84 - // menuSunModel.price = element.menuPrice;  
85 - menuSunModel.price = element.planPrice;  
86 - menuSunModel.member_price = element.memberPrice;  
87 - menuSunModel.unit = '份';  
88 - // menuSunModel.amount = element.amount;  
89 - menuSunModel.cookList = element.cookList;  
90 -  
91 - cookList.add(menuSunModel); 84 + if (element.status == '1') {
  85 + MenuSunModel menuSunModel = MenuSunModel();
  86 + menuSunModel.id = element.id;
  87 + menuSunModel.name = element.pname;
  88 + // menuSunModel.price = element.menuPrice;
  89 + menuSunModel.price = element.planPrice;
  90 + menuSunModel.member_price = element.memberPrice;
  91 + menuSunModel.unit = '份';
  92 + // menuSunModel.amount = element.amount;
  93 + menuSunModel.cookList = element.cookList;
  94 +
  95 + cookList.add(menuSunModel);
  96 + }
92 }); 97 });
93 menuModelSetMeal.cookbooklist = cookList; 98 menuModelSetMeal.cookbooklist = cookList;
94 99
@@ -101,21 +106,24 @@ class _OrderAdvanceEidtPageState extends State<OrderAdvanceEidtPage> { @@ -101,21 +106,24 @@ class _OrderAdvanceEidtPageState extends State<OrderAdvanceEidtPage> {
101 List<MenuSunModel> cookListPlanDish = []; 106 List<MenuSunModel> cookListPlanDish = [];
102 List<SunListPlan> mineList = _planDishProvider.mineListTemp; 107 List<SunListPlan> mineList = _planDishProvider.mineListTemp;
103 mineList.forEach((element) { 108 mineList.forEach((element) {
104 - MenuSunModel menuSunModel = MenuSunModel();  
105 - menuSunModel.id = element.id;  
106 - menuSunModel.name = element.pname;  
107 - menuSunModel.price = element.menuPrice;  
108 - menuSunModel.member_price = element.memberPrice;  
109 - menuSunModel.unit = '份';  
110 - // menuSunModel.amount = element.amount;  
111 - menuSunModel.cookList = element.cookList;  
112 -  
113 - cookListPlanDish.add(menuSunModel); 109 + if (element.status == '1') {
  110 + MenuSunModel menuSunModel = MenuSunModel();
  111 + menuSunModel.id = element.id;
  112 + menuSunModel.name = element.pname;
  113 + menuSunModel.price = element.menuPrice;
  114 + menuSunModel.member_price = element.memberPrice;
  115 + menuSunModel.unit = '份';
  116 + // menuSunModel.amount = element.amount;
  117 + menuSunModel.cookList = element.cookList;
  118 +
  119 + cookListPlanDish.add(menuSunModel);
  120 + }
114 }); 121 });
115 menuModelPlanDish.cookbooklist = cookListPlanDish; 122 menuModelPlanDish.cookbooklist = cookListPlanDish;
116 123
117 _planDishProvider.menuModelForManager 124 _planDishProvider.menuModelForManager
118 .insert(1, menuModelPlanDish); //添加排菜 125 .insert(1, menuModelPlanDish); //添加排菜
  126 + _planDishProvider.pageStateMenu = PageState.Success;
119 127
120 setState(() {}); 128 setState(() {});
121 } else { 129 } else {
@@ -124,6 +132,7 @@ class _OrderAdvanceEidtPageState extends State<OrderAdvanceEidtPage> { @@ -124,6 +132,7 @@ class _OrderAdvanceEidtPageState extends State<OrderAdvanceEidtPage> {
124 } else { 132 } else {
125 // Utils.showToast(''); 133 // Utils.showToast('');
126 } 134 }
  135 + _planDishProvider.pageStateMenu = PageState.ConnectivityError;
127 } 136 }
128 }).catchError((e) { 137 }).catchError((e) {
129 print(e); 138 print(e);
@@ -365,7 +374,7 @@ class _OrderAdvanceEidtPageState extends State<OrderAdvanceEidtPage> { @@ -365,7 +374,7 @@ class _OrderAdvanceEidtPageState extends State<OrderAdvanceEidtPage> {
365 } 374 }
366 375
367 //计算价格 376 //计算价格
368 - _calculatePrice() { 377 + _calculatePrice({String planPrice}) {
369 priceSum = 0; 378 priceSum = 0;
370 memberPriceSum = 0; 379 memberPriceSum = 0;
371 _planDishProvider.menuModelForManager.forEach((element) { 380 _planDishProvider.menuModelForManager.forEach((element) {
@@ -433,7 +442,11 @@ class _OrderAdvanceEidtPageState extends State<OrderAdvanceEidtPage> { @@ -433,7 +442,11 @@ class _OrderAdvanceEidtPageState extends State<OrderAdvanceEidtPage> {
433 }); 442 });
434 } 443 }
435 } 444 }
436 - planDishC.text = priceSum.toString(); 445 + if (planPrice != null) {
  446 + planDishC.text = planPrice;
  447 + } else {
  448 + planDishC.text = priceSum.toString();
  449 + }
437 }); 450 });
438 } 451 }
439 452
@@ -444,7 +457,7 @@ class _OrderAdvanceEidtPageState extends State<OrderAdvanceEidtPage> { @@ -444,7 +457,7 @@ class _OrderAdvanceEidtPageState extends State<OrderAdvanceEidtPage> {
444 backgroundColor: MyColours.color_ffffff, 457 backgroundColor: MyColours.color_ffffff,
445 appBar: SystemAppBar('经理排菜'), 458 appBar: SystemAppBar('经理排菜'),
446 body: Consumer<PlanDishProvider>(builder: (context, model, child) { 459 body: Consumer<PlanDishProvider>(builder: (context, model, child) {
447 - if (model.pageState == PageState.Success) { 460 + if (model.pageStateMenu == PageState.Success) {
448 return Column( 461 return Column(
449 children: [ 462 children: [
450 MyDivider( 463 MyDivider(
@@ -1033,14 +1046,22 @@ class _OrderAdvanceEidtPageState extends State<OrderAdvanceEidtPage> { @@ -1033,14 +1046,22 @@ class _OrderAdvanceEidtPageState extends State<OrderAdvanceEidtPage> {
1033 1046
1034 // Map temp; 1047 // Map temp;
1035 // if (menuModel == null) { 1048 // if (menuModel == null) {
1036 - Map temp = await NavigatorUtil  
1037 - .goOrderEditListShowPage(context, object: {  
1038 - 'object': _planDishProvider.menuModelForManager,  
1039 - }, object1: {  
1040 - 'object1': _planDishProvider.storeList  
1041 - }, object2: {  
1042 - 'object2': _planDishProvider.mineList  
1043 - }); 1049 + FocusScope.of(context)
  1050 + .requestFocus(FocusNode()); //点击空白处隐藏键盘
  1051 + Map temp =
  1052 + await NavigatorUtil.goOrderEditListShowPage(
  1053 + context,
  1054 + object: {
  1055 + 'object':
  1056 + _planDishProvider.menuModelForManager,
  1057 + },
  1058 + object1: {
  1059 + 'object1': _planDishProvider.storeList
  1060 + },
  1061 + object2: {
  1062 + 'object2': _planDishProvider.mineList
  1063 + },
  1064 + planPrice: planDishC.text);
1044 // } else { 1065 // } else {
1045 // temp = 1066 // temp =
1046 // await NavigatorUtil.goPlanNewDishPage( 1067 // await NavigatorUtil.goPlanNewDishPage(
@@ -1055,6 +1076,8 @@ class _OrderAdvanceEidtPageState extends State<OrderAdvanceEidtPage> { @@ -1055,6 +1076,8 @@ class _OrderAdvanceEidtPageState extends State<OrderAdvanceEidtPage> {
1055 temp['more']; //二级菜单 1076 temp['more']; //二级菜单
1056 List<MenuModel> dataLocalShowOne = 1077 List<MenuModel> dataLocalShowOne =
1057 temp['one']; //一级菜单 1078 temp['one']; //一级菜单
  1079 + planDishName = temp['name'];
  1080 + planDishRemark = temp['remark'];
1058 1081
1059 // 刷新页面*************** 1082 // 刷新页面***************
1060 1083
@@ -1128,7 +1151,7 @@ class _OrderAdvanceEidtPageState extends State<OrderAdvanceEidtPage> { @@ -1128,7 +1151,7 @@ class _OrderAdvanceEidtPageState extends State<OrderAdvanceEidtPage> {
1128 1151
1129 carSum = carSumTemp; 1152 carSum = carSumTemp;
1130 print((_planDishProvider.storeList)); 1153 print((_planDishProvider.storeList));
1131 - _calculatePrice(); 1154 + _calculatePrice(planPrice: temp['planPrice']);
1132 _initMenuModelForManagerData(); 1155 _initMenuModelForManagerData();
1133 setState(() {}); 1156 setState(() {});
1134 } 1157 }
@@ -1146,7 +1169,206 @@ class _OrderAdvanceEidtPageState extends State<OrderAdvanceEidtPage> { @@ -1146,7 +1169,206 @@ class _OrderAdvanceEidtPageState extends State<OrderAdvanceEidtPage> {
1146 textColor: MyColours.color_438E93, 1169 textColor: MyColours.color_438E93,
1147 isBold: false, 1170 isBold: false,
1148 onPressed: () { 1171 onPressed: () {
1149 - NavigatorUtil.goOrderPreviewPage(context); 1172 + FocusScope.of(context)
  1173 + .requestFocus(FocusNode()); //点击空白处隐藏键盘
  1174 + List<MenuModel> showList = [];
  1175 + List<MenuSunModel> dataLocalShowMore = []; //二级菜单
  1176 + List<MenuModel> dataLocalShowOne = []; //一级菜单
  1177 +
  1178 + if (_planDishProvider.menuModelForManager != null) {
  1179 + _planDishProvider.menuModelForManager
  1180 + .forEach((element) {
  1181 + if (element.className == '套餐' ||
  1182 + element.className == '我的排菜') {
  1183 + // //如果是套餐,则看cooklist有没有选中的
  1184 + // bool isChange = false; //套餐或者排菜数量是否选中
  1185 + // if (element.className == '套餐') {
  1186 + // isChange = _isChange(widget.storeList);
  1187 + // } else {
  1188 + // // isChange = _isChange(widget.storeList);
  1189 + // }
  1190 +
  1191 + element.cookbooklist.forEach((value) {
  1192 + if (value.amount > 0) {
  1193 + // if (!isChange) {
  1194 + // priceSum += double.parse(value.price) * value.amount;
  1195 + // memberPriceSum +=
  1196 + // double.parse(value.member_price) * value.amount;
  1197 + // }
  1198 + //选中了该套餐
  1199 + //把套餐中没有选中的菜品踢出去
  1200 + MenuSunModel menuSunModel =
  1201 + MenuSunModel();
  1202 + List<MenuModel> moreMenu = [];
  1203 + int moreSum = 0;
  1204 + //遍历套餐中的菜分类
  1205 + value.cookList.forEach((cook) {
  1206 + //遍历套餐中的具体菜品
  1207 + List<MenuSunModel> cooklistSun = [];
  1208 + int cookSum = 0;
  1209 + cook.cookbooklist.forEach((cookSun) {
  1210 + // 具体菜品
  1211 +
  1212 + if (cookSun.amount > 0) {
  1213 + //当前菜品已选择
  1214 + // moreSum += cookSun.amount;
  1215 + cookSum += cookSun.amount;
  1216 +
  1217 + // if (isChange) {
  1218 + // priceSum += double.parse(cookSun.price) * cookSun.amount;
  1219 + // memberPriceSum +=
  1220 + // double.parse(cookSun.member_price) * cookSun.amount;
  1221 + // }
  1222 +
  1223 + carSum += cookSun.amount;
  1224 + cooklistSun.add(cookSun);
  1225 + }
  1226 + });
  1227 + if (cooklistSun.length > 0) {
  1228 + cook.cookbooklist = cooklistSun;
  1229 + cook.allSum = cookSum;
  1230 + moreMenu.add(cook);
  1231 + value.cookList = moreMenu;
  1232 + }
  1233 + });
  1234 + value.moreSum = value.amount;
  1235 + value.channel = element.className == '套餐'
  1236 + ? '1'
  1237 + : '2'; // 1套餐----2排菜
  1238 + dataLocalShowMore.add(value);
  1239 + }
  1240 + });
  1241 + } else if (element.className == '店内常点') {
  1242 + // //如果是我的排菜,则看cooklist有没有选中的
  1243 +
  1244 + // bool hasmMine =
  1245 + // element.cookbooklist.any(((value) => value.amount > 0));
  1246 + // if (hasmMine) {
  1247 + // //套餐中有被选中
  1248 + // maxIndex++;
  1249 + // }
  1250 + } else if (element.className == '临时加菜') {
  1251 + } else {
  1252 + //单菜
  1253 + bool hasmMenu = element.cookbooklist
  1254 + .any(((value) => value.amount > 0));
  1255 + if (hasmMenu) {
  1256 + //单品此类有选中菜品
  1257 + MenuModel menuModel = MenuModel();
  1258 + menuModel.className = element.className;
  1259 + menuModel.classLabel = element.classLabel;
  1260 + menuModel.classType = element.classType;
  1261 + menuModel.id = element.id;
  1262 + menuModel.order = element.order;
  1263 + menuModel.sellerid = element.sellerid;
  1264 + menuModel.status = element.status;
  1265 + menuModel.cookbooklist = [];
  1266 + List<MenuSunModel> cookbooklist = [];
  1267 + int allSum = 0;
  1268 + element.cookbooklist.forEach((value) {
  1269 + if (value.amount > 0) {
  1270 + allSum += value.amount;
  1271 + // priceSum += double.parse(value.price) * value.amount;
  1272 + // memberPriceSum +=
  1273 + // double.parse(value.member_price) * value.amount;
  1274 + carSum += value.amount;
  1275 + cookbooklist.add(value);
  1276 + }
  1277 + });
  1278 + menuModel.allSum = allSum;
  1279 + menuModel.cookbooklist.addAll(cookbooklist);
  1280 + dataLocalShowOne.add(menuModel);
  1281 + }
  1282 + }
  1283 + // planDishC.text = priceSum.toString();
  1284 + });
  1285 + }
  1286 +
  1287 + dataLocalShowMore.forEach((value) {
  1288 + value.cookList.forEach((newValue) {
  1289 + if (showList.length == 0) {
  1290 + showList.add(
  1291 + MenuModel.fromJson2(newValue.toJson()));
  1292 + } else {
  1293 + bool hasC = false;
  1294 + showList.forEach((show) {
  1295 + if (show.id == newValue.id) {
  1296 + hasC = true;
  1297 + //数据存在相同菜类
  1298 +
  1299 + newValue.cookbooklist.forEach((newcook) {
  1300 + bool has = false;
  1301 + show.cookbooklist.forEach((oldshow) {
  1302 + if (oldshow.id == newcook.id) {
  1303 + //同一个菜品
  1304 + has = true;
  1305 + oldshow.amount += newcook.amount;
  1306 + show.allSum += newcook.amount;
  1307 + }
  1308 + });
  1309 + if (!has) {
  1310 + //旧的里面没有该菜品
  1311 + show.cookbooklist.add(newcook);
  1312 + }
  1313 + });
  1314 + }
  1315 + });
  1316 + if (!hasC) {
  1317 + showList.add(
  1318 + MenuModel.fromJson2(newValue.toJson()));
  1319 + }
  1320 + }
  1321 + });
  1322 + });
  1323 +
  1324 + print(showList);
  1325 +
  1326 + dataLocalShowOne.forEach((element) {
  1327 + if (showList.length == 0) {
  1328 + showList
  1329 + .add(MenuModel.fromJson2(element.toJson()));
  1330 + } else {
  1331 + bool hasC = false;
  1332 + showList.forEach((show) {
  1333 + if (show.id == element.id) {
  1334 + hasC = true;
  1335 + //数据存在相同菜类
  1336 +
  1337 + element.cookbooklist.forEach((newcook) {
  1338 + bool has = false;
  1339 + show.cookbooklist.forEach((oldshow) {
  1340 + if (oldshow.id == newcook.id) {
  1341 + //同一个菜品
  1342 + has = true;
  1343 + oldshow.amount += newcook.amount;
  1344 + show.allSum += newcook.amount;
  1345 + }
  1346 + });
  1347 + if (!has) {
  1348 + //旧的里面没有该菜品
  1349 + show.cookbooklist.add(newcook);
  1350 + }
  1351 + });
  1352 + }
  1353 + });
  1354 + if (!hasC) {
  1355 + showList.add(
  1356 + MenuModel.fromJson2(element.toJson()));
  1357 + }
  1358 + }
  1359 + });
  1360 + // double priceSum = 0; //总计
  1361 + // double memberPriceSum = 0; //会员价
  1362 + // TextEditingController planDishC =
  1363 + // TextEditingController(); //排菜价
  1364 +
  1365 + NavigatorUtil.goOrderPreviewPage(context,
  1366 + object: {'object': showList},
  1367 + name: planDishName,
  1368 + remark: planDishRemark,
  1369 + priceSum: priceSum.toString(),
  1370 + memberPriceSum: memberPriceSum.toString(),
  1371 + planDishText: planDishC.text);
1150 }, 1372 },
1151 ), 1373 ),
1152 RoundButton( 1374 RoundButton(
@@ -20,7 +20,9 @@ class OrderEditListShowPage extends StatefulWidget { @@ -20,7 +20,9 @@ class OrderEditListShowPage extends StatefulWidget {
20 final List<SunListPlan> storeList; //套餐元数据 20 final List<SunListPlan> storeList; //套餐元数据
21 final List<SunListPlan> mineList; //我的排菜元数据 21 final List<SunListPlan> mineList; //我的排菜元数据
22 final List<MenuModel> data; 22 final List<MenuModel> data;
23 - OrderEditListShowPage({Key key, this.data, this.storeList, this.mineList}) 23 + final String planPrice;
  24 + OrderEditListShowPage(
  25 + {Key key, this.data, this.storeList, this.mineList, this.planPrice})
24 : super(key: key); 26 : super(key: key);
25 27
26 @override 28 @override
@@ -37,6 +39,12 @@ class _OrderEditListShowPageState extends State<OrderEditListShowPage> { @@ -37,6 +39,12 @@ class _OrderEditListShowPageState extends State<OrderEditListShowPage> {
37 double memberPriceSum = 0; //会员价 39 double memberPriceSum = 0; //会员价
38 TextEditingController planDishC = TextEditingController(); //排菜价 40 TextEditingController planDishC = TextEditingController(); //排菜价
39 41
  42 + List<SunListPlan> storeListLocal = []; //把amount = 0 的筛选出去
  43 + List<SunListPlan> mineListLocal = []; //把amount = 0 的筛选出去
  44 +
  45 + TextEditingController planDishName = TextEditingController(); //排菜名称
  46 + TextEditingController planDishRemark = TextEditingController(); //排菜备注
  47 +
40 Widget _laduWidget() { 48 Widget _laduWidget() {
41 // if (labelIcon[widget 49 // if (labelIcon[widget
42 // .cookBookList.labelList[index].icon] is int) { 50 // .cookBookList.labelList[index].icon] is int) {
@@ -167,7 +175,35 @@ class _OrderEditListShowPageState extends State<OrderEditListShowPage> { @@ -167,7 +175,35 @@ class _OrderEditListShowPageState extends State<OrderEditListShowPage> {
167 // planDishC.text = priceSum.toString(); 175 // planDishC.text = priceSum.toString();
168 }); 176 });
169 } 177 }
  178 + if (widget.storeList != null) {
  179 + SunListPlan sunListPlanTemp = SunListPlan();
  180 + widget.storeList.forEach((sunListPlan) {
  181 + sunListPlanTemp = sunListPlan;
  182 + sunListPlanTemp.cookList.forEach((menuModel) {
  183 + menuModel.cookbooklist.removeWhere((element) => element.amount == 0);
  184 + });
  185 + sunListPlanTemp.cookList
  186 + .removeWhere((element) => element.cookbooklist.length == 0);
  187 + print(sunListPlanTemp);
  188 + storeListLocal.add(sunListPlanTemp);
  189 + });
  190 +
  191 + SunListPlan sunListPlanTempMine = SunListPlan();
  192 + widget.mineList.forEach((sunListPlan) {
  193 + sunListPlanTempMine = sunListPlan;
  194 + sunListPlanTempMine.cookList.forEach((menuModel) {
  195 + menuModel.cookbooklist.removeWhere((element) => element.amount == 0);
  196 + });
  197 + sunListPlanTempMine.cookList
  198 + .removeWhere((element) => element.cookbooklist.length == 0);
  199 + print(sunListPlanTemp);
  200 + mineListLocal.add(sunListPlanTempMine);
  201 + });
  202 + }
170 _calculatePrice(); 203 _calculatePrice();
  204 + if (widget.planPrice != null) {
  205 + planDishC.text = widget.planPrice;
  206 + }
171 print(dataLocalShowMore); 207 print(dataLocalShowMore);
172 print(dataLocalShowOne); 208 print(dataLocalShowOne);
173 } 209 }
@@ -179,22 +215,24 @@ class _OrderEditListShowPageState extends State<OrderEditListShowPage> { @@ -179,22 +215,24 @@ class _OrderEditListShowPageState extends State<OrderEditListShowPage> {
179 dataLocalShowMore.forEach((element) { 215 dataLocalShowMore.forEach((element) {
180 if (element.channel == '1' || element.channel == '2') { 216 if (element.channel == '1' || element.channel == '2') {
181 List<SunListPlan> olddata = 217 List<SunListPlan> olddata =
182 - element.channel == '1' ? widget.storeList : widget.mineList; 218 + element.channel == '1' ? storeListLocal : mineListLocal;
183 olddata.forEach((store) { 219 olddata.forEach((store) {
184 if (element.amount > 0) { 220 if (element.amount > 0) {
185 if (store.id == element.id) { 221 if (store.id == element.id) {
186 bool isChange = false; //套餐数量是否发生变化 222 bool isChange = false; //套餐数量是否发生变化
187 //同一个套餐 223 //同一个套餐
  224 +
188 store.cookList.forEach((storeCook) { 225 store.cookList.forEach((storeCook) {
189 - if (store.cookList.length != element.cookList.length) { 226 + if (store.cookList.length > element.cookList.length) {
  227 + //删除了整个菜品分类
190 isChange = true; 228 isChange = true;
191 } 229 }
192 element.cookList.forEach((cooklist) { 230 element.cookList.forEach((cooklist) {
193 if (cooklist.id == storeCook.id) { 231 if (cooklist.id == storeCook.id) {
194 - if (cooklist.cookbooklist.length !=  
195 - storeCook.cookbooklist.length) {  
196 - isChange = true;  
197 - } 232 + // if (cooklist.cookbooklist.length !=
  233 + // storeCook.cookbooklist.length) {
  234 + // isChange = true;
  235 + // }
198 //同一分类 236 //同一分类
199 cooklist.cookbooklist.forEach((value1) { 237 cooklist.cookbooklist.forEach((value1) {
200 storeCook.cookbooklist.forEach((value2) { 238 storeCook.cookbooklist.forEach((value2) {
@@ -263,6 +301,7 @@ class _OrderEditListShowPageState extends State<OrderEditListShowPage> { @@ -263,6 +301,7 @@ class _OrderEditListShowPageState extends State<OrderEditListShowPage> {
263 }); 301 });
264 } 302 }
265 }); 303 });
  304 +
266 planDishC.text = priceSum.toString(); 305 planDishC.text = priceSum.toString();
267 } 306 }
268 307
@@ -313,6 +352,21 @@ class _OrderEditListShowPageState extends State<OrderEditListShowPage> { @@ -313,6 +352,21 @@ class _OrderEditListShowPageState extends State<OrderEditListShowPage> {
313 // } 352 // }
314 // } 353 // }
315 354
  355 + // 数组拷贝
  356 + List copyWithList(List list) {
  357 + List copyList = [];
  358 + for (var item in list) {
  359 + if (item is Map) {
  360 + copyList.add(Map.from(item));
  361 + } else if (item is List) {
  362 + copyList.add(copyWithList(item));
  363 + } else {
  364 + copyList.add(item);
  365 + }
  366 + }
  367 + return copyList;
  368 + }
  369 +
316 @override 370 @override
317 Widget build(BuildContext context) { 371 Widget build(BuildContext context) {
318 return KeyboardDismissOnTap( 372 return KeyboardDismissOnTap(
@@ -351,7 +405,7 @@ class _OrderEditListShowPageState extends State<OrderEditListShowPage> { @@ -351,7 +405,7 @@ class _OrderEditListShowPageState extends State<OrderEditListShowPage> {
351 Expanded( 405 Expanded(
352 child: TextField( 406 child: TextField(
353 maxLines: 1, 407 maxLines: 1,
354 - // controller: 408 + controller: planDishName,
355 // focusNode: _focusNode, 409 // focusNode: _focusNode,
356 // autofocus: true, 410 // autofocus: true,
357 411
@@ -1435,7 +1489,7 @@ class _OrderEditListShowPageState extends State<OrderEditListShowPage> { @@ -1435,7 +1489,7 @@ class _OrderEditListShowPageState extends State<OrderEditListShowPage> {
1435 color: MyColours.color_DBDBDB)), 1489 color: MyColours.color_DBDBDB)),
1436 child: TextField( 1490 child: TextField(
1437 maxLines: 4, 1491 maxLines: 4,
1438 - // controller: 1492 + controller: planDishRemark,
1439 // focusNode: _focusNode, 1493 // focusNode: _focusNode,
1440 // autofocus: true, 1494 // autofocus: true,
1441 1495
@@ -1642,7 +1696,93 @@ class _OrderEditListShowPageState extends State<OrderEditListShowPage> { @@ -1642,7 +1696,93 @@ class _OrderEditListShowPageState extends State<OrderEditListShowPage> {
1642 fontSize: 32, 1696 fontSize: 32,
1643 isBold: false, 1697 isBold: false,
1644 onPressed: () { 1698 onPressed: () {
1645 - NavigatorUtil.goOrderPreviewPage(context); 1699 + FocusScope.of(context)
  1700 + .requestFocus(FocusNode()); //点击空白处隐藏键盘
  1701 + List<MenuModel> showList = [];
  1702 +
  1703 + dataLocalShowMore.forEach((value) {
  1704 + value.cookList.forEach((newValue) {
  1705 + if (showList.length == 0) {
  1706 + showList
  1707 + .add(MenuModel.fromJson2(newValue.toJson()));
  1708 + } else {
  1709 + bool hasC = false;
  1710 + showList.forEach((show) {
  1711 + if (show.id == newValue.id) {
  1712 + hasC = true;
  1713 + //数据存在相同菜类
  1714 +
  1715 + newValue.cookbooklist.forEach((newcook) {
  1716 + bool has = false;
  1717 + show.cookbooklist.forEach((oldshow) {
  1718 + if (oldshow.id == newcook.id) {
  1719 + //同一个菜品
  1720 + has = true;
  1721 + oldshow.amount += newcook.amount;
  1722 + show.allSum += newcook.amount;
  1723 + }
  1724 + });
  1725 + if (!has) {
  1726 + //旧的里面没有该菜品
  1727 + show.cookbooklist.add(newcook);
  1728 + }
  1729 + });
  1730 + }
  1731 + });
  1732 + if (!hasC) {
  1733 + showList
  1734 + .add(MenuModel.fromJson2(newValue.toJson()));
  1735 + }
  1736 + }
  1737 + });
  1738 + });
  1739 +
  1740 + print(showList);
  1741 +
  1742 + dataLocalShowOne.forEach((element) {
  1743 + if (showList.length == 0) {
  1744 + showList.add(MenuModel.fromJson2(element.toJson()));
  1745 + } else {
  1746 + bool hasC = false;
  1747 + showList.forEach((show) {
  1748 + if (show.id == element.id) {
  1749 + hasC = true;
  1750 + //数据存在相同菜类
  1751 +
  1752 + element.cookbooklist.forEach((newcook) {
  1753 + bool has = false;
  1754 + show.cookbooklist.forEach((oldshow) {
  1755 + if (oldshow.id == newcook.id) {
  1756 + //同一个菜品
  1757 + has = true;
  1758 + oldshow.amount += newcook.amount;
  1759 + show.allSum += newcook.amount;
  1760 + }
  1761 + });
  1762 + if (!has) {
  1763 + //旧的里面没有该菜品
  1764 + show.cookbooklist.add(newcook);
  1765 + }
  1766 + });
  1767 + }
  1768 + });
  1769 + if (!hasC) {
  1770 + showList.add(MenuModel.fromJson2(element.toJson()));
  1771 + }
  1772 + }
  1773 + });
  1774 + // double priceSum = 0; //总计
  1775 + // double memberPriceSum = 0; //会员价
  1776 + // TextEditingController planDishC =
  1777 + // TextEditingController(); //排菜价
  1778 +
  1779 + NavigatorUtil.goOrderPreviewPage(context,
  1780 + object: {'object': showList},
  1781 + name: planDishName.text,
  1782 + remark: planDishRemark.text,
  1783 + priceSum: priceSum.toString(),
  1784 + memberPriceSum: memberPriceSum.toString(),
  1785 + planDishText: planDishC.text);
1646 }, 1786 },
1647 ), 1787 ),
1648 HEmptyView(30), 1788 HEmptyView(30),
@@ -1661,6 +1801,9 @@ class _OrderEditListShowPageState extends State<OrderEditListShowPage> { @@ -1661,6 +1801,9 @@ class _OrderEditListShowPageState extends State<OrderEditListShowPage> {
1661 Map data = { 1801 Map data = {
1662 'more': dataLocalShowMore, 1802 'more': dataLocalShowMore,
1663 'one': dataLocalShowOne, 1803 'one': dataLocalShowOne,
  1804 + 'planPrice': planDishC.text,
  1805 + 'name': planDishName.text,
  1806 + 'remark': planDishRemark.text
1664 }; 1807 };
1665 1808
1666 Navigator.of(context).pop(data); 1809 Navigator.of(context).pop(data);
1 import 'package:flutter/material.dart'; 1 import 'package:flutter/material.dart';
  2 +import 'package:one_key/utils/repaint_boundary_utils.dart';
2 import 'package:one_key/widgets/system_app_bar.dart'; 3 import 'package:one_key/widgets/system_app_bar.dart';
  4 +import 'package:provider/provider.dart';
3 5
4 import '../../../res/colors.dart'; 6 import '../../../res/colors.dart';
5 import '../../../utils/screen_util.dart'; 7 import '../../../utils/screen_util.dart';
@@ -8,12 +10,29 @@ import '../../../widgets/MyDivider.dart'; @@ -8,12 +10,29 @@ import '../../../widgets/MyDivider.dart';
8 import '../../../widgets/h_empty_view.dart'; 10 import '../../../widgets/h_empty_view.dart';
9 import '../../../widgets/round_button.dart'; 11 import '../../../widgets/round_button.dart';
10 import '../../../widgets/v_empty_view.dart'; 12 import '../../../widgets/v_empty_view.dart';
  13 +import '../../models/cookbook_model.dart';
  14 +import '../../provider/user_model.dart';
  15 +import '../../utils/share_helper.dart';
11 16
12 /** 17 /**
13 * 生成的预览页 18 * 生成的预览页
14 */ 19 */
15 class OrderPreviewPage extends StatefulWidget { 20 class OrderPreviewPage extends StatefulWidget {
16 - OrderPreviewPage({Key key}) : super(key: key); 21 + final List<MenuModel> showList;
  22 + final String priceSum;
  23 + final String memberPriceSum;
  24 + final String planDishText;
  25 + final String name;
  26 + final String remark;
  27 + OrderPreviewPage(
  28 + {Key key,
  29 + this.showList,
  30 + this.priceSum,
  31 + this.memberPriceSum,
  32 + this.planDishText,
  33 + this.name,
  34 + this.remark})
  35 + : super(key: key);
17 36
18 @override 37 @override
19 _OrderPreviewPageState createState() => _OrderPreviewPageState(); 38 _OrderPreviewPageState createState() => _OrderPreviewPageState();
@@ -21,6 +40,8 @@ class OrderPreviewPage extends StatefulWidget { @@ -21,6 +40,8 @@ class OrderPreviewPage extends StatefulWidget {
21 40
22 class _OrderPreviewPageState extends State<OrderPreviewPage> { 41 class _OrderPreviewPageState extends State<OrderPreviewPage> {
23 ScrollController controller = ScrollController(); 42 ScrollController controller = ScrollController();
  43 + //全局key-截图key
  44 + final GlobalKey boundaryKey = GlobalKey();
24 45
25 @override 46 @override
26 void initState() { 47 void initState() {
@@ -52,6 +73,10 @@ class _OrderPreviewPageState extends State<OrderPreviewPage> { @@ -52,6 +73,10 @@ class _OrderPreviewPageState extends State<OrderPreviewPage> {
52 73
53 @override 74 @override
54 Widget build(BuildContext context) { 75 Widget build(BuildContext context) {
  76 + String sellername =
  77 + Provider.of<UserModel>(context, listen: false).user.sellername;
  78 + String sellerAdr =
  79 + Provider.of<UserModel>(context, listen: false).user.sellerAddr;
55 return Scaffold( 80 return Scaffold(
56 backgroundColor: MyColours.color_ffffff, 81 backgroundColor: MyColours.color_ffffff,
57 body: Column( 82 body: Column(
@@ -59,327 +84,397 @@ class _OrderPreviewPageState extends State<OrderPreviewPage> { @@ -59,327 +84,397 @@ class _OrderPreviewPageState extends State<OrderPreviewPage> {
59 Expanded( 84 Expanded(
60 child: SingleChildScrollView( 85 child: SingleChildScrollView(
61 controller: controller, 86 controller: controller,
62 - child: Column(children: [  
63 - Container(  
64 - width: double.infinity,  
65 - margin: EdgeInsets.zero,  
66 - padding: EdgeInsets.only(  
67 - left: w(20), right: w(20), top: w(30), bottom: w(15)),  
68 - // height: w(200),  
69 - // constraints: new BoxConstraints.expand(  
70 - // height: w(200),  
71 - // ),  
72 - decoration: BoxDecoration(  
73 - image: DecorationImage(  
74 - image: AssetImage(Utils.getImgPath('preview_bg')),  
75 - fit: BoxFit.cover 87 + child: RepaintBoundary(
  88 + key: boundaryKey,
  89 + child: Container(
  90 + color: Colors.white,
  91 + child: Column(children: [
  92 + Container(
  93 + width: double.infinity,
  94 + margin: EdgeInsets.zero,
  95 + padding: EdgeInsets.only(
  96 + left: w(20),
  97 + right: w(20),
  98 + top: w(30),
  99 + bottom: w(15)),
  100 + // height: w(200),
  101 + // constraints: new BoxConstraints.expand(
  102 + // height: w(200),
  103 + // ),
  104 + decoration: BoxDecoration(
  105 + image: DecorationImage(
  106 + image: AssetImage(
  107 + Utils.getImgPath('preview_bg')),
  108 + fit: BoxFit.cover
76 109
77 - // centerSlice: new Rect.fromLTRB(270.0, 180.0, 1360.0, 730.0),  
78 - )), 110 + // centerSlice: new Rect.fromLTRB(270.0, 180.0, 1360.0, 730.0),
  111 + )),
79 112
80 - child: Column(  
81 - crossAxisAlignment: CrossAxisAlignment.start,  
82 - children: [  
83 - Text(  
84 - '14号酒庄 贵宾排菜菜单',  
85 - style: TextStyle(  
86 - fontSize: font(20),  
87 - fontWeight: FontWeight.bold,  
88 - color: MyColours.color_CFB53B),  
89 - ),  
90 - VEmptyView(26),  
91 - Text(  
92 - '预定贵宾 | 刘生先生',  
93 - style: TextStyle(  
94 - fontSize: font(14),  
95 - color: MyColours.color_303030),  
96 - ),  
97 - VEmptyView(10),  
98 - Text(  
99 - '预定时间 | 2022年11月11日 晚餐',  
100 - style: TextStyle(  
101 - fontSize: font(14),  
102 - color: MyColours.color_303030),  
103 - ),  
104 - VEmptyView(10),  
105 - Text(  
106 - '区域桌台 | 一楼包间 108、一楼包间 108、一楼包间 108、一楼包间 108、一楼包间 108',  
107 - style: TextStyle(  
108 - fontSize: font(14),  
109 - color: MyColours.color_303030),  
110 - ),  
111 - VEmptyView(10),  
112 - Text(  
113 - '餐厅地址 | 唐山市路北区拥军道88号',  
114 - style: TextStyle(  
115 - fontSize: font(14),  
116 - color: MyColours.color_303030),  
117 - ),  
118 - VEmptyView(10),  
119 - Text(  
120 - '专属服务 | 张山山 18866668888',  
121 - style: TextStyle(  
122 - fontSize: font(14),  
123 - color: MyColours.color_303030),  
124 - ),  
125 - ],  
126 - ),  
127 - ),  
128 - Container(  
129 - width: double.infinity,  
130 - // width: w(32),  
131 - height: w(48),  
132 - padding: EdgeInsets.only(left: w(10), right: w(20)),  
133 - decoration: BoxDecoration(  
134 - border: Border(  
135 - // top: BorderSide(  
136 - // width: w(1), color: MyColours.color_DBDBDB),  
137 - bottom: BorderSide(  
138 - width: w(1),  
139 - color: MyColours.color_DBDBDB))),  
140 - // constraints: BoxConstraints(minWidth: w(20)),  
141 - child: Row(  
142 - children: [  
143 - Expanded(  
144 - child: TextField(  
145 - maxLines: 1,  
146 - // controller:  
147 - // focusNode: _focusNode,  
148 - // autofocus: true,  
149 -  
150 - style: TextStyle(  
151 - color: MyColours.color_515151,  
152 - fontSize: font(16),  
153 - fontWeight: FontWeight.bold),  
154 - textAlign: TextAlign.left,  
155 - // textAlignVertical: TextAlignVertical.center,  
156 - decoration: InputDecoration(  
157 - // hintText: "请输入排菜名称",  
158 - hintText: '朋友小聚888套餐(若无名称不展示本行)',  
159 - hintStyle: TextStyle(  
160 - color: MyColours.color_999999,  
161 - fontSize: font(16),  
162 - fontWeight: FontWeight.bold),  
163 - // isCollapsed:  
164 - // true, //重点,相当于高度包裹的意思,必须设置为true,不然有默认奇妙的最小高度  
165 - border: OutlineInputBorder(  
166 - borderSide: BorderSide.none),  
167 - contentPadding: EdgeInsets.zero, 113 + child: Column(
  114 + crossAxisAlignment: CrossAxisAlignment.start,
  115 + children: [
  116 + Text(
  117 + '${sellername} 贵宾排菜菜单',
  118 + style: TextStyle(
  119 + fontSize: font(20),
  120 + fontWeight: FontWeight.bold,
  121 + color: MyColours.color_CFB53B),
  122 + ),
  123 + VEmptyView(26),
  124 + Text(
  125 + '预定贵宾 | 刘生先生',
  126 + style: TextStyle(
  127 + fontSize: font(14),
  128 + color: MyColours.color_303030),
  129 + ),
  130 + VEmptyView(10),
  131 + Text(
  132 + '预定时间 | 2022年11月11日 晚餐',
  133 + style: TextStyle(
  134 + fontSize: font(14),
  135 + color: MyColours.color_303030),
  136 + ),
  137 + VEmptyView(10),
  138 + Text(
  139 + '区域桌台 | 一楼包间 108、一楼包间 108、一楼包间 108、一楼包间 108、一楼包间 108',
  140 + style: TextStyle(
  141 + fontSize: font(14),
  142 + color: MyColours.color_303030),
  143 + ),
  144 + VEmptyView(10),
  145 + Text(
  146 + '餐厅地址 | ${sellerAdr}',
  147 + style: TextStyle(
  148 + fontSize: font(14),
  149 + color: MyColours.color_303030),
  150 + ),
  151 + VEmptyView(10),
  152 + Text(
  153 + '专属服务 | 张山山 18866668888',
  154 + style: TextStyle(
  155 + fontSize: font(14),
  156 + color: MyColours.color_303030),
  157 + ),
  158 + ],
168 ), 159 ),
169 - keyboardType: TextInputType.text,  
170 - textInputAction: TextInputAction.done,  
171 -  
172 - onChanged: (value) {  
173 - // setState(() {});  
174 - // _searchSellerLocation();  
175 - // customerProvider.searchData(value);  
176 - },  
177 - onEditingComplete: () {  
178 - FocusScope.of(context)  
179 - .requestFocus(FocusNode()); //点击空白处隐藏键盘  
180 - // contantShowModel.searchData(  
181 - // contantShowModel.controller.text);  
182 - // _searchSellerLocation();  
183 - // _focusNode.unfocus();  
184 - },  
185 - )),  
186 - Text(  
187 - '1份',  
188 - style: TextStyle(  
189 - fontSize: font(14),  
190 - color: MyColours.color_515151),  
191 ), 160 ),
192 - ],  
193 - )),  
194 - ListView.builder(  
195 - itemCount: 20,  
196 - shrinkWrap: true,  
197 - controller: controller,  
198 - itemBuilder: (context, index) {  
199 - return ListView.builder(  
200 - itemCount: 2 + 1,  
201 - shrinkWrap: true,  
202 - controller: controller,  
203 - itemBuilder: (context, index) {  
204 - if (index == 0) {  
205 - return Column(  
206 - children: [  
207 - //头  
208 - Container(  
209 - width: double.infinity,  
210 - // width: w(32),  
211 - height: w(48),  
212 - padding: EdgeInsets.only(  
213 - left: w(10), right: w(20)), 161 + widget.name != null && widget.name != ''
  162 + ? Container(
  163 + width: double.infinity,
  164 + // width: w(32),
  165 + // constraints: BoxConstraints(
  166 + // minHeight: w(48),
  167 + // ),
  168 + // height: w(48),
  169 + padding: EdgeInsets.only(
  170 + left: w(10),
  171 + right: w(20),
  172 + top: w(10),
  173 + bottom: w(10)),
  174 + decoration: BoxDecoration(
  175 + border: Border(
  176 + // top: BorderSide(
  177 + // width: w(1), color: MyColours.color_DBDBDB),
  178 + bottom: BorderSide(
  179 + width: w(1),
  180 + color:
  181 + MyColours.color_DBDBDB))),
  182 + // constraints: BoxConstraints(minWidth: w(20)),
  183 + child: Row(
  184 + children: [
  185 + Expanded(
  186 + child: Text(
  187 + widget.name,
  188 + style: TextStyle(
  189 + color: MyColours.color_515151,
  190 + fontSize: font(16),
  191 + fontWeight: FontWeight.bold),
  192 + )
  193 + // TextField(
  194 + // maxLines: 1,
  195 + // // controller:
  196 + // // focusNode: _focusNode,
  197 + // // autofocus: true,
  198 +
  199 + // style: TextStyle(
  200 + // color: MyColours.color_515151,
  201 + // fontSize: font(16),
  202 + // fontWeight: FontWeight.bold),
  203 + // textAlign: TextAlign.left,
  204 + // // textAlignVertical: TextAlignVertical.center,
  205 + // decoration: InputDecoration(
  206 + // // hintText: "请输入排菜名称",
  207 + // hintText: '朋友小聚888套餐(若无名称不展示本行)',
  208 + // hintStyle: TextStyle(
  209 + // color: MyColours.color_999999,
  210 + // fontSize: font(16),
  211 + // fontWeight: FontWeight.bold),
  212 + // // isCollapsed:
  213 + // // true, //重点,相当于高度包裹的意思,必须设置为true,不然有默认奇妙的最小高度
  214 + // border: OutlineInputBorder(
  215 + // borderSide: BorderSide.none),
  216 + // contentPadding: EdgeInsets.zero,
  217 + // ),
  218 + // keyboardType: TextInputType.text,
  219 + // textInputAction: TextInputAction.done,
  220 +
  221 + // onChanged: (value) {
  222 + // // setState(() {});
  223 + // // _searchSellerLocation();
  224 + // // customerProvider.searchData(value);
  225 + // },
  226 + // onEditingComplete: () {
  227 + // FocusScope.of(context)
  228 + // .requestFocus(FocusNode()); //点击空白处隐藏键盘
  229 + // // contantShowModel.searchData(
  230 + // // contantShowModel.controller.text);
  231 + // // _searchSellerLocation();
  232 + // // _focusNode.unfocus();
  233 + // },
  234 + // )
  235 + ),
  236 + HEmptyView(20),
  237 + Text(
  238 + '1份',
  239 + style: TextStyle(
  240 + fontSize: font(14),
  241 + color: MyColours.color_515151),
  242 + ),
  243 + ],
  244 + ))
  245 + : SizedBox(),
  246 + ListView.builder(
  247 + itemCount: widget.showList.length,
  248 + shrinkWrap: true,
  249 + controller: controller,
  250 + padding: EdgeInsets.zero,
  251 + itemBuilder: (context, index) {
  252 + MenuModel menuModel = widget.showList[index];
  253 + return ListView.builder(
  254 + itemCount:
  255 + menuModel.cookbooklist.length + 1,
  256 + shrinkWrap: true,
  257 + controller: controller,
  258 + padding: EdgeInsets.zero,
  259 + itemBuilder: (context, index) {
  260 + if (index == 0) {
  261 + return Column(
  262 + children: [
  263 + //头
  264 + Container(
  265 + width: double.infinity,
  266 + // width: w(32),
  267 + height: w(48),
  268 + padding: EdgeInsets.only(
  269 + left: w(10),
  270 + right: w(20)),
  271 + decoration: BoxDecoration(
  272 + border: Border(
  273 + bottom: BorderSide(
  274 + width: w(1),
  275 + color: MyColours
  276 + .color_DBDBDB))),
  277 + // constraints: BoxConstraints(minWidth: w(20)),
  278 + child: Row(
  279 + mainAxisAlignment:
  280 + MainAxisAlignment
  281 + .spaceBetween,
  282 + children: [
  283 + Text(
  284 + menuModel.className,
  285 + style: TextStyle(
  286 + fontSize: font(16),
  287 + color: MyColours
  288 + .color_515151,
  289 + fontWeight:
  290 + FontWeight
  291 + .bold),
  292 + ),
  293 + Text(
  294 + '${menuModel.allSum}道',
  295 + style: TextStyle(
  296 + fontSize: font(14),
  297 + color: MyColours
  298 + .color_515151,
  299 + ),
  300 + ),
  301 + ],
  302 + ))
  303 + ],
  304 + );
  305 + }
  306 + int indexReal = index - 1;
  307 + MenuSunModel menuSunModel =
  308 + menuModel.cookbooklist[indexReal];
  309 + return Container(
  310 + padding: EdgeInsets.symmetric(
  311 + horizontal: w(20),
  312 + vertical: w(13)),
214 decoration: BoxDecoration( 313 decoration: BoxDecoration(
215 border: Border( 314 border: Border(
216 bottom: BorderSide( 315 bottom: BorderSide(
217 width: w(1), 316 width: w(1),
218 color: MyColours 317 color: MyColours
219 .color_DBDBDB))), 318 .color_DBDBDB))),
220 - // constraints: BoxConstraints(minWidth: w(20)),  
221 child: Row( 319 child: Row(
222 - mainAxisAlignment:  
223 - MainAxisAlignment.spaceBetween,  
224 children: [ 320 children: [
225 - Text(  
226 - '热菜', 321 + // Container(
  322 + // constraints: BoxConstraints(
  323 + // maxWidth: w(80)),
  324 + Expanded(
  325 + child: Text(
  326 + menuSunModel.name,
  327 + maxLines: 10,
  328 + overflow: TextOverflow.ellipsis,
227 style: TextStyle( 329 style: TextStyle(
228 - fontSize: font(16), 330 + fontSize: font(14),
229 color: 331 color:
230 - MyColours.color_515151,  
231 - fontWeight:  
232 - FontWeight.bold),  
233 - ), 332 + MyColours.color_515151),
  333 + )),
  334 + // HEmptyView(8),
  335 + // _laduWidget(),
  336 + Spacer(),
234 Text( 337 Text(
235 - '6道', 338 + '${menuSunModel.price}元/${menuSunModel.unit}',
  339 + maxLines: 2,
  340 + overflow: TextOverflow.ellipsis,
236 style: TextStyle( 341 style: TextStyle(
237 - fontSize: font(14),  
238 - color: MyColours.color_515151,  
239 - ), 342 + fontSize: font(12),
  343 + color:
  344 + MyColours.color_515151),
240 ), 345 ),
  346 + // HEmptyView(108),
  347 + // Text(
  348 + // '38元/份',
  349 + // maxLines: 2,
  350 + // overflow: TextOverflow.ellipsis,
  351 + // style: TextStyle(
  352 + // fontSize: font(10),
  353 + // color: MyColours.color_8EBBBE),
  354 + // ),
  355 + Container(
  356 + width: w(79),
  357 + alignment:
  358 + Alignment.centerRight,
  359 + child: Text(
  360 + '${menuSunModel.amount}份',
  361 + style: TextStyle(
  362 + fontSize: font(12),
  363 + color: MyColours
  364 + .color_515151),
  365 + )),
241 ], 366 ],
242 - ))  
243 - ],  
244 - );  
245 - }  
246 - int indexReal = index - 1;  
247 - return Container(  
248 - padding: EdgeInsets.symmetric(  
249 - horizontal: w(20), vertical: w(13)),  
250 - decoration: BoxDecoration(  
251 - border: Border(  
252 - bottom: BorderSide(  
253 - width: w(1),  
254 - color: MyColours.color_DBDBDB))),  
255 - child: Row( 367 + ),
  368 + );
  369 + });
  370 + }),
  371 + widget.remark != null && widget.remark != ''
  372 + ? Container(
  373 + width: double.infinity,
  374 + padding: EdgeInsets.symmetric(
  375 + horizontal: w(15), vertical: w(7)),
  376 + margin: EdgeInsets.only(
  377 + top: w(7),
  378 + bottom: w(13),
  379 + left: w(20),
  380 + right: w(20)),
  381 + decoration: BoxDecoration(
  382 + borderRadius:
  383 + BorderRadius.circular(r(5)),
  384 + border: Border.all(
  385 + width: w(1),
  386 + color: MyColours.color_DBDBDB)),
  387 + child: Text(
  388 + "${widget.remark}",
  389 + style: TextStyle(
  390 + color: MyColours.color_515151,
  391 + fontSize: font(12)),
  392 + )
  393 + // child: TextField(
  394 + // maxLines: 4,
  395 + // // controller:
  396 + // // focusNode: _focusNode,
  397 + // // autofocus: true,
  398 +
  399 + // style: TextStyle(
  400 + // color: MyColours.color_515151, fontSize: font(12)),
  401 + // textAlign: TextAlign.left,
  402 + // // textAlignVertical: TextAlignVertical.center,
  403 + // decoration: InputDecoration(
  404 + // hintText: "请输入整单备注",
  405 + // hintStyle: TextStyle(
  406 + // color: MyColours.color_999999,
  407 + // fontSize: font(12),
  408 + // ),
  409 + // // isCollapsed:
  410 + // // true, //重点,相当于高度包裹的意思,必须设置为true,不然有默认奇妙的最小高度
  411 + // border:
  412 + // OutlineInputBorder(borderSide: BorderSide.none),
  413 + // contentPadding: EdgeInsets.zero,
  414 + // ),
  415 + // keyboardType: TextInputType.number,
  416 + // textInputAction: TextInputAction.done,
  417 +
  418 + // onChanged: (value) {
  419 + // // setState(() {});
  420 + // // _searchSellerLocation();
  421 + // // customerProvider.searchData(value);
  422 + // },
  423 + // onEditingComplete: () {
  424 + // FocusScope.of(context)
  425 + // .requestFocus(FocusNode()); //点击空白处隐藏键盘
  426 + // // contantShowModel.searchData(
  427 + // // contantShowModel.controller.text);
  428 + // // _searchSellerLocation();
  429 + // // _focusNode.unfocus();
  430 + // },
  431 + // ),
  432 + )
  433 + : SizedBox(),
  434 + Container(
  435 + decoration: BoxDecoration(
  436 + border: Border(
  437 + top: BorderSide(
  438 + width: w(1),
  439 + color: MyColours.color_DBDBDB))),
  440 + padding: EdgeInsets.symmetric(
  441 + horizontal: w(10), vertical: w(15)),
  442 + child: Row(
  443 + mainAxisAlignment:
  444 + MainAxisAlignment.spaceAround,
256 children: [ 445 children: [
257 - Container(  
258 - constraints:  
259 - BoxConstraints(maxWidth: w(80)),  
260 - child: Text(  
261 - '山城辣子鸡',  
262 - maxLines: 10,  
263 - overflow: TextOverflow.ellipsis,  
264 - style: TextStyle(  
265 - fontSize: font(14),  
266 - color: MyColours.color_515151),  
267 - )),  
268 - HEmptyView(8),  
269 - _laduWidget(),  
270 - Spacer(),  
271 Text( 446 Text(
272 - '38元/份',  
273 - maxLines: 2,  
274 - overflow: TextOverflow.ellipsis, 447 + '总计',
275 style: TextStyle( 448 style: TextStyle(
276 fontSize: font(12), 449 fontSize: font(12),
277 color: MyColours.color_515151), 450 color: MyColours.color_515151),
278 ), 451 ),
279 - HEmptyView(108),  
280 - // Text(  
281 - // '38元/份',  
282 - // maxLines: 2,  
283 - // overflow: TextOverflow.ellipsis,  
284 - // style: TextStyle(  
285 - // fontSize: font(10),  
286 - // color: MyColours.color_8EBBBE),  
287 - // ),  
288 Text( 452 Text(
289 - '1份', 453 + '菜单价:${widget.priceSum}元',
290 style: TextStyle( 454 style: TextStyle(
291 fontSize: font(12), 455 fontSize: font(12),
292 color: MyColours.color_515151), 456 color: MyColours.color_515151),
293 ), 457 ),
294 - ],  
295 - ),  
296 - );  
297 - });  
298 - }),  
299 - Container(  
300 - padding: EdgeInsets.symmetric(  
301 - horizontal: w(15), vertical: w(7)),  
302 - margin: EdgeInsets.only(  
303 - top: w(7), bottom: w(13), left: w(20), right: w(20)),  
304 - decoration: BoxDecoration(  
305 - borderRadius: BorderRadius.circular(r(5)),  
306 - border: Border.all(  
307 - width: w(1), color: MyColours.color_DBDBDB)),  
308 - child: TextField(  
309 - maxLines: 4,  
310 - // controller:  
311 - // focusNode: _focusNode,  
312 - // autofocus: true,  
313 -  
314 - style: TextStyle(  
315 - color: MyColours.color_515151, fontSize: font(12)),  
316 - textAlign: TextAlign.left,  
317 - // textAlignVertical: TextAlignVertical.center,  
318 - decoration: InputDecoration(  
319 - hintText: "请输入整单备注",  
320 - hintStyle: TextStyle(  
321 - color: MyColours.color_999999,  
322 - fontSize: font(12),  
323 - ),  
324 - // isCollapsed:  
325 - // true, //重点,相当于高度包裹的意思,必须设置为true,不然有默认奇妙的最小高度  
326 - border:  
327 - OutlineInputBorder(borderSide: BorderSide.none),  
328 - contentPadding: EdgeInsets.zero,  
329 - ),  
330 - keyboardType: TextInputType.number,  
331 - textInputAction: TextInputAction.done,  
332 -  
333 - onChanged: (value) {  
334 - // setState(() {});  
335 - // _searchSellerLocation();  
336 - // customerProvider.searchData(value);  
337 - },  
338 - onEditingComplete: () {  
339 - FocusScope.of(context)  
340 - .requestFocus(FocusNode()); //点击空白处隐藏键盘  
341 - // contantShowModel.searchData(  
342 - // contantShowModel.controller.text);  
343 - // _searchSellerLocation();  
344 - // _focusNode.unfocus();  
345 - },  
346 - ),  
347 - ),  
348 - ]))),  
349 - Container(  
350 - decoration: BoxDecoration(  
351 - border: Border(  
352 - top: BorderSide(  
353 - width: w(1), color: MyColours.color_DBDBDB))),  
354 - padding: EdgeInsets.symmetric(horizontal: w(10), vertical: w(15)),  
355 - child: Row(  
356 - mainAxisAlignment: MainAxisAlignment.spaceAround,  
357 - children: [  
358 - Text(  
359 - '总计',  
360 - style: TextStyle(  
361 - fontSize: font(12), color: MyColours.color_515151),  
362 - ),  
363 - Text(  
364 - '菜单价:1164元',  
365 - style: TextStyle(  
366 - fontSize: font(12), color: MyColours.color_515151),  
367 - ),  
368 - Text(  
369 - '会员价:1125元',  
370 - style: TextStyle(  
371 - fontSize: font(12), color: MyColours.color_515151),  
372 - ),  
373 - Text(  
374 - '排菜价:1100元',  
375 - style: TextStyle(  
376 - fontSize: font(12), color: MyColours.color_515151),  
377 - )  
378 - ])),  
379 - Text(  
380 - '周到安排技术支持 400-000-9690',  
381 - style: TextStyle(fontSize: font(12), color: MyColours.color_999999),  
382 - ), 458 + Text(
  459 + '会员价:${widget.memberPriceSum}元',
  460 + style: TextStyle(
  461 + fontSize: font(12),
  462 + color: MyColours.color_515151),
  463 + ),
  464 + Text(
  465 + '排菜价:${widget.planDishText}元',
  466 + style: TextStyle(
  467 + fontSize: font(12),
  468 + color: MyColours.color_515151),
  469 + )
  470 + ])),
  471 + Text(
  472 + '周到安排技术支持 400-000-9690',
  473 + style: TextStyle(
  474 + fontSize: font(12),
  475 + color: MyColours.color_999999),
  476 + ),
  477 + ]))))),
383 Container( 478 Container(
384 color: MyColours.color_ffffff, 479 color: MyColours.color_ffffff,
385 padding: EdgeInsets.only( 480 padding: EdgeInsets.only(
@@ -414,6 +509,8 @@ class _OrderPreviewPageState extends State<OrderPreviewPage> { @@ -414,6 +509,8 @@ class _OrderPreviewPageState extends State<OrderPreviewPage> {
414 fontSize: 36, 509 fontSize: 36,
415 isBold: false, 510 isBold: false,
416 onPressed: () { 511 onPressed: () {
  512 + ShareHelper.onShareWx(context,
  513 + boundaryKey: boundaryKey);
417 // NavigatorUtil.goOrderPreviewPage(context); 514 // NavigatorUtil.goOrderPreviewPage(context);
418 }, 515 },
419 ), 516 ),
@@ -20,6 +20,8 @@ class PlanDishProvider extends ChangeNotifier { @@ -20,6 +20,8 @@ class PlanDishProvider extends ChangeNotifier {
20 PageState pageStateMine = PageState.Success; 20 PageState pageStateMine = PageState.Success;
21 PageState pageStateMy = PageState.Loading; 21 PageState pageStateMy = PageState.Loading;
22 22
  23 + PageState pageStateMenu = PageState.Loading;
  24 +
23 List<MenuModel> menuModel; //菜品数据 25 List<MenuModel> menuModel; //菜品数据
24 List<MenuModel> menuModelForManager = []; //经理点菜菜品数据 26 List<MenuModel> menuModelForManager = []; //经理点菜菜品数据
25 27
@@ -1249,6 +1249,12 @@ class NavigatorUtil { @@ -1249,6 +1249,12 @@ class NavigatorUtil {
1249 static Future<dynamic> goOrderPreviewPage( 1249 static Future<dynamic> goOrderPreviewPage(
1250 BuildContext context, { 1250 BuildContext context, {
1251 replace = false, 1251 replace = false,
  1252 + Map object,
  1253 + String priceSum,
  1254 + String memberPriceSum,
  1255 + String planDishText,
  1256 + String name,
  1257 + String remark,
1252 }) { 1258 }) {
1253 // if (invoice != null) { 1259 // if (invoice != null) {
1254 // return _navigateTo(context, 1260 // return _navigateTo(context,
@@ -1259,14 +1265,19 @@ class NavigatorUtil { @@ -1259,14 +1265,19 @@ class NavigatorUtil {
1259 // return _navigateTo(context, 1265 // return _navigateTo(context,
1260 // "${Routes.order_advance_home_page}?tids=$tids&tableidNow=$tableidNow&fromPage=$fromPage&canChoose=$canChoose&object=${FluroConvertUtils.object2string(object)}"); 1266 // "${Routes.order_advance_home_page}?tids=$tids&tableidNow=$tableidNow&fromPage=$fromPage&canChoose=$canChoose&object=${FluroConvertUtils.object2string(object)}");
1261 // } 1267 // }
1262 - return _navigateTo(context, "${Routes.order_preview_page}", 1268 + return _navigateTo(context,
  1269 + "${Routes.order_preview_page}?object=${FluroConvertUtils.object2string(object)}&priceSum=$priceSum&memberPriceSum=$memberPriceSum&planDishText=$planDishText&name=${Uri.encodeComponent(name)}&remark=${Uri.encodeComponent(remark)}",
1263 replace: replace); 1270 replace: replace);
1264 } 1271 }
1265 1272
1266 ///经理排菜-编辑列表展示 1273 ///经理排菜-编辑列表展示
1267 1274
1268 static Future<dynamic> goOrderEditListShowPage(BuildContext context, 1275 static Future<dynamic> goOrderEditListShowPage(BuildContext context,
1269 - {replace = false, Map object, Map object1, Map object2}) { 1276 + {replace = false,
  1277 + Map object,
  1278 + Map object1,
  1279 + Map object2,
  1280 + String planPrice}) {
1270 // if (invoice != null) { 1281 // if (invoice != null) {
1271 // return _navigateTo(context, 1282 // return _navigateTo(context,
1272 // "${Routes.order_advance_home_page}?invoice=${FluroConvertUtils.object2string(invoice)}", 1283 // "${Routes.order_advance_home_page}?invoice=${FluroConvertUtils.object2string(invoice)}",
@@ -1274,7 +1285,7 @@ class NavigatorUtil { @@ -1274,7 +1285,7 @@ class NavigatorUtil {
1274 // } 1285 // }
1275 if (object != null) { 1286 if (object != null) {
1276 return _navigateTo(context, 1287 return _navigateTo(context,
1277 - "${Routes.order_edit_list_show_page}?object=${FluroConvertUtils.object2string(object)}&object1=${FluroConvertUtils.object2string(object1)}&object2=${FluroConvertUtils.object2string(object2)}"); 1288 + "${Routes.order_edit_list_show_page}?object=${FluroConvertUtils.object2string(object)}&object1=${FluroConvertUtils.object2string(object1)}&object2=${FluroConvertUtils.object2string(object2)}&planPrice=$planPrice");
1278 } 1289 }
1279 return _navigateTo(context, "${Routes.order_edit_list_show_page}", 1290 return _navigateTo(context, "${Routes.order_edit_list_show_page}",
1280 replace: replace); 1291 replace: replace);
@@ -1986,8 +1986,37 @@ var orderPreviewPageHandle = new Handler( @@ -1986,8 +1986,37 @@ var orderPreviewPageHandle = new Handler(
1986 // res.add(TableList.fromJson(item)); 1986 // res.add(TableList.fromJson(item));
1987 // } 1987 // }
1988 // } 1988 // }
  1989 +
  1990 + List<MenuModel> res = [];
  1991 + // String planDishPrice = '';
  1992 + if (params.keys.contains('object')) {
  1993 + Map object = FluroConvertUtils.string2map(params["object"].first);
  1994 + List temp = object['object'];
  1995 +
  1996 + // planDishPrice = params["planDishPrice"].first;
  1997 +
  1998 + for (var item in temp) {
  1999 + // MenuModel menuModel = MenuModel.fromJson2(item);
  2000 + // res.add(menuModel);
  2001 + // print(res);
  2002 + res.add(MenuModel.fromJson2(item));
  2003 + }
  2004 + }
  2005 + String priceSum = params["priceSum"].first;
  2006 + String memberPriceSum = params["memberPriceSum"].first;
  2007 + String planDishText = params["planDishText"].first;
  2008 + String name = params["name"].first;
  2009 + String remark = params["remark"].first;
  2010 +
1989 return ChangeNotifierProvider<PlanDishProvider>( 2011 return ChangeNotifierProvider<PlanDishProvider>(
1990 - create: (_) => PlanDishProvider(), child: OrderPreviewPage()); 2012 + create: (_) => PlanDishProvider(),
  2013 + child: OrderPreviewPage(
  2014 + showList: res,
  2015 + priceSum: priceSum,
  2016 + memberPriceSum: memberPriceSum,
  2017 + planDishText: planDishText,
  2018 + name: name,
  2019 + remark: remark));
1991 }); 2020 });
1992 2021
1993 ///经理排菜---排菜编辑列表展示 2022 ///经理排菜---排菜编辑列表展示
@@ -2029,7 +2058,6 @@ var orderEditListShowPageHandle = new Handler( @@ -2029,7 +2058,6 @@ var orderEditListShowPageHandle = new Handler(
2029 List temp = object['object1']; 2058 List temp = object['object1'];
2030 // SunListPlan plan = SunListPlan(); 2059 // SunListPlan plan = SunListPlan();
2031 // plan. 2060 // plan.
2032 - // planDishPrice = params["planDishPrice"].first;  
2033 2061
2034 for (var item in temp) { 2062 for (var item in temp) {
2035 // MenuModel menuModel = MenuModel.fromJson2(item); 2063 // MenuModel menuModel = MenuModel.fromJson2(item);
@@ -2054,8 +2082,13 @@ var orderEditListShowPageHandle = new Handler( @@ -2054,8 +2082,13 @@ var orderEditListShowPageHandle = new Handler(
2054 } 2082 }
2055 } 2083 }
2056 2084
  2085 + String planPrice = params["planPrice"].first;
  2086 +
2057 return OrderEditListShowPage( 2087 return OrderEditListShowPage(
2058 - data: res, storeList: storeList, mineList: mineList); 2088 + data: res,
  2089 + storeList: storeList,
  2090 + mineList: mineList,
  2091 + planPrice: planPrice);
2059 }); 2092 });
2060 2093
2061 ///经理排菜--类型选择 2094 ///经理排菜--类型选择
  1 +/*
  2 + * @Author: 王长春
  3 + * @Date: 2022-03-14 09:24:34
  4 + * @LastEditors: 王长春
  5 + * @LastEditTime: 2022-03-17 10:01:41
  6 + * @Description: 截图工具,生成截图,保存到相册或者保存本地cash文件夹返回文件路径(供分享使用)
  7 + */
  8 +
  9 +import 'dart:io';
  10 +import 'dart:typed_data';
  11 +import 'dart:async';
  12 +import 'dart:ui';
  13 +import 'dart:ui' as ui;
  14 +import 'package:flutter/material.dart';
  15 +import 'package:flutter/rendering.dart';
  16 +// import 'package:flutter_easyloading/flutter_easyloading.dart';
  17 +
  18 +import 'package:image_gallery_saver/image_gallery_saver.dart';
  19 +import 'package:one_key/utils/utils.dart';
  20 +import 'package:path_provider/path_provider.dart';
  21 +import 'package:permission_handler/permission_handler.dart';
  22 +
  23 +class RepaintBoundaryUtils {
  24 + //全局key-截图key
  25 + // final GlobalKey boundaryKey = GlobalKey();
  26 +//生成截图
  27 + /// 截屏图片生成图片流ByteData
  28 + Future<String> captureImage(boundaryKey) async {
  29 + RenderRepaintBoundary boundary =
  30 + boundaryKey.currentContext.findRenderObject() as RenderRepaintBoundary;
  31 + double dpr = ui.window.devicePixelRatio; // 获取当前设备的像素比
  32 + var image = await boundary.toImage(pixelRatio: dpr);
  33 + // 将image转化成byte
  34 + ByteData byteData = await image.toByteData(format: ImageByteFormat.png);
  35 +
  36 + var filePath = "";
  37 +
  38 + Uint8List pngBytes = byteData.buffer.asUint8List();
  39 + // 获取手机存储(getTemporaryDirectory临时存储路径)
  40 + Directory applicationDir = await getTemporaryDirectory();
  41 + // getApplicationDocumentsDirectory();
  42 + // 判断路径是否存在
  43 + bool isDirExist = await Directory(applicationDir.path).exists();
  44 + if (!isDirExist) Directory(applicationDir.path).create();
  45 + // 直接保存,返回的就是保存后的文件
  46 + File saveFile = await File(
  47 + applicationDir.path + "${DateTime.now().toIso8601String()}.jpg")
  48 + .writeAsBytes(pngBytes);
  49 + filePath = saveFile.path;
  50 + // if (Platform.isAndroid) {
  51 + // // 如果是Android 的话,直接使用image_gallery_saver就可以了
  52 + // // 图片byte数据转化unit8
  53 + // Uint8List images = byteData!.buffer.asUint8List();
  54 + // // 调用image_gallery_saver的saveImages方法,返回值就是图片保存后的路径
  55 + // String result = await ImageGallerySaver.saveImage(images);
  56 + // // 需要去除掉file://开头。生成要使用的file
  57 + // File saveFile = new File(result.replaceAll("file://", ""));
  58 + // filePath = saveFile.path;
  59 + //
  60 + //
  61 + // } else if (Platform.isIOS) {
  62 + // // 图片byte数据转化unit8
  63 + //
  64 + // }
  65 +
  66 + return filePath;
  67 + }
  68 +
  69 +//申请存本地相册权限
  70 + Future<bool> getPormiation() async {
  71 + if (Platform.isIOS) {
  72 + var status = await Permission.photos.status;
  73 + if (status.isDenied) {
  74 + Map<Permission, PermissionStatus> statuses = await [
  75 + Permission.photos,
  76 + ].request();
  77 + // saveImage(globalKey);
  78 + }
  79 + return status.isGranted;
  80 + } else {
  81 + var status = await Permission.storage.status;
  82 + if (status.isDenied) {
  83 + Map<Permission, PermissionStatus> statuses = await [
  84 + Permission.storage,
  85 + ].request();
  86 + }
  87 + return status.isGranted;
  88 + }
  89 + }
  90 +
  91 +//保存到相册
  92 + void savePhoto(boundaryKey) async {
  93 + RenderRepaintBoundary boundary =
  94 + boundaryKey.currentContext.findRenderObject() as RenderRepaintBoundary;
  95 +
  96 + double dpr = ui.window.devicePixelRatio; // 获取当前设备的像素比
  97 + var image = await boundary.toImage(pixelRatio: dpr);
  98 + // 将image转化成byte
  99 + ByteData byteData = await image.toByteData(format: ImageByteFormat.png);
  100 + //获取保存相册权限,如果没有,则申请改权限
  101 + bool permition = await getPormiation();
  102 +
  103 + var status = await Permission.photos.status;
  104 + if (permition) {
  105 + if (Platform.isIOS) {
  106 + if (status.isGranted) {
  107 + Uint8List images = byteData.buffer.asUint8List();
  108 + final result = await ImageGallerySaver.saveImage(images,
  109 + quality: 60, name: "hello");
  110 + Utils.showToast("保存成功");
  111 + }
  112 + if (status.isDenied) {
  113 + print("IOS拒绝");
  114 + }
  115 + } else {
  116 + //安卓
  117 + if (status.isGranted) {
  118 + print("Android已授权");
  119 + Uint8List images = byteData.buffer.asUint8List();
  120 + final result = await ImageGallerySaver.saveImage(images, quality: 60);
  121 + if (result != null) {
  122 + Utils.showToast("保存成功");
  123 + } else {
  124 + print('error');
  125 + // toast("保存失败");
  126 + }
  127 + }
  128 + }
  129 + } else {
  130 + //重新请求--第一次请求权限时,保存方法不会走,需要重新调一次
  131 + savePhoto(boundaryKey);
  132 + }
  133 + }
  134 +}
  1 +/*
  2 + * @Author: 王长春
  3 + * @Date: 2022-03-15 15:17:19
  4 + * @LastEditors: 王长春
  5 + * @LastEditTime: 2022-03-16 19:15:45
  6 + * @Description: 分享工具
  7 + */
  8 +
  9 +import 'package:flutter/material.dart';
  10 +import 'package:one_key/utils/repaint_boundary_utils.dart';
  11 +// import 'package:flutter_easyloading/flutter_easyloading.dart';
  12 +import 'package:one_key/utils/utils.dart';
  13 +import 'package:one_key/utils/wx_sdk.dart';
  14 +// import 'package:organization/common/utils/repaintBoundary_utils.dart';
  15 +// import 'package:organization/common/utils/wechatSDK.dart';
  16 +// import 'package:share_plus/share_plus.dart';
  17 +
  18 +class ShareHelper {
  19 +
  20 + static bool wxIsInstalled = false;
  21 +//微信分享截图
  22 + static void onShareWx(BuildContext context,{boundaryKey}) async {
  23 +
  24 + wxIsInstalled = await WxSdk.wxIsInstalled();
  25 + //收回键盘,如果有输入的情况下,先收回键盘,再截图
  26 + FocusScope.of(context).requestFocus(FocusNode());
  27 +
  28 + if (wxIsInstalled) {
  29 + //分享
  30 + // WxSdk.ShareText("sdgsfds",title:"标题");
  31 + //获取截图地址
  32 + String filePath = await RepaintBoundaryUtils().captureImage(boundaryKey);
  33 +
  34 + print(filePath);
  35 + WxSdk.ShareImage(title: "机构检索", decs: "", file: filePath);
  36 + } else {
  37 + //提示未安装微信
  38 + Utils.showToast("未安装微信");
  39 + }
  40 + }
  41 +
  42 + // static void checkWx() async {
  43 + // wxIsInstalled = await WxSdk.wxIsInstalled();
  44 + // }
  45 +
  46 +
  47 +}
  48 +
  1 +import 'dart:io';
  2 +import 'dart:typed_data';
  3 +// import 'check.dart';
  4 +import 'package:fluwx/fluwx.dart' as fluwx;
  5 +
  6 +class WxSdk {
  7 + // static bool wxIsInstalled;
  8 + static Future init() async {
  9 + fluwx.registerWxApi(
  10 + appId: "这里写你注册的appid",
  11 + doOnAndroid: true,
  12 + doOnIOS: true,
  13 + universalLink: "这里写你注册的universalLink");
  14 + }
  15 +
  16 + static Future<bool> wxIsInstalled() async {
  17 + return await fluwx.isWeChatInstalled;
  18 + }
  19 +
  20 + /**
  21 + * 分享图片到微信,
  22 + * file=本地路径
  23 + * url=网络地址
  24 + * asset=内置在app的资源图片
  25 + * scene=分享场景,1好友会话,2朋友圈,3收藏
  26 + */
  27 + static void ShareImage(
  28 + {String title,
  29 + String decs,
  30 + String file,
  31 + String url,
  32 + String asset,
  33 + int scene = 1}) async {
  34 + fluwx.WeChatScene wxScene = fluwx.WeChatScene.SESSION;
  35 + if (scene == 2) {
  36 + wxScene = fluwx.WeChatScene.TIMELINE;
  37 + } else if (scene == 3) {
  38 + wxScene = fluwx.WeChatScene.FAVORITE;
  39 + }
  40 + fluwx.WeChatShareImageModel model;
  41 +
  42 + if (file != null) {
  43 + model = fluwx.WeChatShareImageModel(fluwx.WeChatImage.file(File(file)),
  44 + title: title, description: decs, scene: wxScene);
  45 + } else if (url != null) {
  46 + model = fluwx.WeChatShareImageModel(fluwx.WeChatImage.network(url),
  47 + title: title, description: decs, scene: wxScene);
  48 + } else if (asset != null) {
  49 + model = fluwx.WeChatShareImageModel(fluwx.WeChatImage.asset(asset),
  50 + title: title, description: decs, scene: wxScene);
  51 + } else {
  52 + throw Exception("缺少图片资源信息");
  53 + }
  54 + fluwx.shareToWeChat(model);
  55 + }
  56 +
  57 + /**
  58 + * 分享文本
  59 + * content=分享内容
  60 + * scene=分享场景,1好友会话,2朋友圈,3收藏
  61 + */
  62 + static void ShareText(String content, {String title, int scene = 1}) {
  63 + fluwx.WeChatScene wxScene = fluwx.WeChatScene.SESSION;
  64 + if (scene == 2) {
  65 + wxScene = fluwx.WeChatScene.TIMELINE;
  66 + } else if (scene == 3) {
  67 + wxScene = fluwx.WeChatScene.FAVORITE;
  68 + }
  69 + fluwx.WeChatShareTextModel model =
  70 + fluwx.WeChatShareTextModel(content, title: title, scene: wxScene);
  71 + fluwx.shareToWeChat(model);
  72 + }
  73 +
  74 +/***
  75 + * 分享视频
  76 + * videoUrl=视频网上地址
  77 + * thumbFile=缩略图本地路径
  78 + * scene=分享场景,1好友会话,2朋友圈,3收藏
  79 + */
  80 + static void ShareVideo(String videoUrl,
  81 + {String thumbFile, String title, String desc, int scene = 1}) {
  82 + fluwx.WeChatScene wxScene = fluwx.WeChatScene.SESSION;
  83 + if (scene == 2) {
  84 + wxScene = fluwx.WeChatScene.TIMELINE;
  85 + } else if (scene == 3) {
  86 + wxScene = fluwx.WeChatScene.FAVORITE;
  87 + }
  88 + fluwx.WeChatImage image;
  89 + if (thumbFile != null) {
  90 + image = fluwx.WeChatImage.file(File(thumbFile));
  91 + }
  92 + var model = fluwx.WeChatShareVideoModel(
  93 + videoUrl: videoUrl,
  94 + thumbnail: image,
  95 + title: title,
  96 + description: desc,
  97 + scene: wxScene);
  98 + fluwx.shareToWeChat(model);
  99 + }
  100 +
  101 + /**
  102 + * 分享链接
  103 + * url=链接
  104 + * thumbFile=缩略图本地路径
  105 + * scene=分享场景,1好友会话,2朋友圈,3收藏
  106 + */
  107 +
  108 + static bool strNoEmpty(String str) {
  109 + if (str == null || str == '') {
  110 + return false;
  111 + }
  112 + return true;
  113 + }
  114 +
  115 + static void ShareUrl(String url,
  116 + {String thumbFile,
  117 + Uint8List thumbBytes,
  118 + String title,
  119 + String desc,
  120 + int scene = 1,
  121 + String networkThumb,
  122 + String assetThumb}) {
  123 + desc = desc ?? "";
  124 + title = title ?? "";
  125 + if (desc.length > 54) {
  126 + desc = desc.substring(0, 54) + "...";
  127 + }
  128 + if (title.length > 20) {
  129 + title = title.substring(0, 20) + "...";
  130 + }
  131 + fluwx.WeChatScene wxScene = fluwx.WeChatScene.SESSION;
  132 + if (scene == 2) {
  133 + wxScene = fluwx.WeChatScene.TIMELINE;
  134 + } else if (scene == 3) {
  135 + wxScene = fluwx.WeChatScene.FAVORITE;
  136 + }
  137 + fluwx.WeChatImage image;
  138 + if (thumbFile != null) {
  139 + image = fluwx.WeChatImage.file(File(thumbFile));
  140 + } else if (thumbBytes != null) {
  141 + image = fluwx.WeChatImage.binary(thumbBytes);
  142 + } else if (strNoEmpty(networkThumb)) {
  143 + image = fluwx.WeChatImage.network(Uri.encodeFull(networkThumb));
  144 + } else if (strNoEmpty(assetThumb)) {
  145 + image = fluwx.WeChatImage.asset(assetThumb, suffix: ".png");
  146 + }
  147 + var model = fluwx.WeChatShareWebPageModel(
  148 + url,
  149 + thumbnail: image,
  150 + title: title,
  151 + description: desc,
  152 + scene: wxScene,
  153 + );
  154 + fluwx.shareToWeChat(model);
  155 + }
  156 +}
@@ -623,6 +623,13 @@ packages: @@ -623,6 +623,13 @@ packages:
623 url: "https://pub.flutter-io.cn" 623 url: "https://pub.flutter-io.cn"
624 source: hosted 624 source: hosted
625 version: "4.0.1" 625 version: "4.0.1"
  626 + image_gallery_saver:
  627 + dependency: "direct main"
  628 + description:
  629 + name: image_gallery_saver
  630 + url: "https://pub.flutter-io.cn"
  631 + source: hosted
  632 + version: "1.7.1"
626 image_picker: 633 image_picker:
627 dependency: "direct main" 634 dependency: "direct main"
628 description: 635 description:
@@ -177,6 +177,7 @@ dependencies: @@ -177,6 +177,7 @@ dependencies:
177 flutter_keyboard_visibility: ^5.3.0 177 flutter_keyboard_visibility: ^5.3.0
178 # 178 #
179 extended_text_field: ^10.1.1 179 extended_text_field: ^10.1.1
  180 + image_gallery_saver: ^1.7.1
180 181
181 182
182 183