Commit 8c14b97950c7876a4e02577765c12130d7265a73

Authored by wdn127929
1 parent 5eec861b

修复裁剪图点击x后未取消转圈

@@ -219,45 +219,84 @@ class _BookInfoPageState extends State<BookInfoPage> { @@ -219,45 +219,84 @@ class _BookInfoPageState extends State<BookInfoPage> {
219 Uint8List newImg = await Utils.testFromFileComporessList( 219 Uint8List newImg = await Utils.testFromFileComporessList(
220 context, afterImg, 220 context, afterImg,
221 needResize: true); 221 needResize: true);
222 - path = await Utils.saveImage(newImg);  
223 - } 222 + if (newImg != null) {
  223 + path = await Utils.saveImage(newImg);
  224 + if (path == null) {
  225 + File compressedFile = await FlutterNativeImage.compressImage(
  226 + pickedFile.path,
  227 + quality: 70,
  228 + percentage: 50);
  229 + path = compressedFile.path;
  230 + }
224 231
225 - if (path == null) {  
226 - File compressedFile = await FlutterNativeImage.compressImage(  
227 - pickedFile.path,  
228 - quality: 70,  
229 - percentage: 50);  
230 - path = compressedFile.path;  
231 - } 232 + // File compressedFile = await FlutterNativeImage.compressImage(
  233 + // pickedFile.path,
  234 + // quality: 50,
  235 + // percentage: 50);
  236 + setState(() {
  237 + if (pickedFile != null) {
  238 + imgModel.file = File(pickedFile.path);
  239 + imgModel.process = 0.01;
  240 + } else {
  241 + print('No image selected.');
  242 + }
  243 + });
  244 + if (pickedFile != null) {
  245 + // if (title == '头像') {
  246 + // _uploadImageProvider.imgSizeTouxiang = 76;
  247 + // _uploadImageProvider.touxiang.qiniuUrl = null;
  248 + // } else {
  249 + // _uploadImageProvider.imgSizeErweima = 76;
  250 + // _uploadImageProvider.firstImage.qiniuUrl = null;
  251 + imgModel.qiniuUrl = null;
  252 + // }
  253 + bool need = await Utils.sizeNeed(File(pickedFile.path));
  254 + File file = File(pickedFile.path);
  255 + if (need) {
  256 + file = File(path);
  257 + }
  258 + UploadImageUtil()
  259 + .startUploadOnly(context, file, type, true, _uploadImageProvider);
  260 + }
  261 + }
  262 + } else {
  263 + if (path == null) {
  264 + File compressedFile = await FlutterNativeImage.compressImage(
  265 + pickedFile.path,
  266 + quality: 70,
  267 + percentage: 50);
  268 + path = compressedFile.path;
  269 + }
232 270
233 - // File compressedFile = await FlutterNativeImage.compressImage(  
234 - // pickedFile.path,  
235 - // quality: 50,  
236 - // percentage: 50);  
237 - setState(() { 271 + // File compressedFile = await FlutterNativeImage.compressImage(
  272 + // pickedFile.path,
  273 + // quality: 50,
  274 + // percentage: 50);
  275 + setState(() {
  276 + if (pickedFile != null) {
  277 + imgModel.file = File(pickedFile.path);
  278 + imgModel.process = 0.01;
  279 + } else {
  280 + print('No image selected.');
  281 + }
  282 + });
238 if (pickedFile != null) { 283 if (pickedFile != null) {
239 - imgModel.file = File(pickedFile.path);  
240 - imgModel.process = 0.01;  
241 - } else {  
242 - print('No image selected.');  
243 - }  
244 - });  
245 - if (pickedFile != null) {  
246 - // if (title == '头像') {  
247 - // _uploadImageProvider.imgSizeTouxiang = 76;  
248 - // _uploadImageProvider.touxiang.qiniuUrl = null;  
249 - // } else {  
250 - // _uploadImageProvider.imgSizeErweima = 76;  
251 - // _uploadImageProvider.firstImage.qiniuUrl = null;  
252 - imgModel.qiniuUrl = null;  
253 - // }  
254 - bool need = await Utils.sizeNeed(File(pickedFile.path));  
255 - File file = File(pickedFile.path);  
256 - if (need) {  
257 - file = File(path); 284 + // if (title == '头像') {
  285 + // _uploadImageProvider.imgSizeTouxiang = 76;
  286 + // _uploadImageProvider.touxiang.qiniuUrl = null;
  287 + // } else {
  288 + // _uploadImageProvider.imgSizeErweima = 76;
  289 + // _uploadImageProvider.firstImage.qiniuUrl = null;
  290 + imgModel.qiniuUrl = null;
  291 + // }
  292 + bool need = await Utils.sizeNeed(File(pickedFile.path));
  293 + File file = File(pickedFile.path);
  294 + if (need) {
  295 + file = File(path);
  296 + }
  297 + UploadImageUtil()
  298 + .startUploadOnly(context, file, type, true, _uploadImageProvider);
258 } 299 }
259 - UploadImageUtil()  
260 - .startUploadOnly(context, file, type, true, _uploadImageProvider);  
261 } 300 }
262 } 301 }
263 302
@@ -794,7 +833,7 @@ class _BookInfoPageState extends State<BookInfoPage> { @@ -794,7 +833,7 @@ class _BookInfoPageState extends State<BookInfoPage> {
794 if (qiniuUrl != null && qiniuUrl != '') { 833 if (qiniuUrl != null && qiniuUrl != '') {
795 // _uploadImageProvider.logo.process = 0; 834 // _uploadImageProvider.logo.process = 0;
796 // setState(() { 835 // setState(() {
797 - 836 +
798 // }); 837 // });
799 // setState(() {}); 838 // setState(() {});
800 // tempList.add(qiniuUrl); 839 // tempList.add(qiniuUrl);
@@ -635,29 +635,31 @@ class _StoreBaseInfoPageState extends State<StoreBaseInfoPage> { @@ -635,29 +635,31 @@ class _StoreBaseInfoPageState extends State<StoreBaseInfoPage> {
635 Uint8List afterImg = await yourFile.readAsBytes(); 635 Uint8List afterImg = await yourFile.readAsBytes();
636 Uint8List newImg = await Utils.testFromFileComporessList(context, afterImg, 636 Uint8List newImg = await Utils.testFromFileComporessList(context, afterImg,
637 needResize: true); 637 needResize: true);
638 - String path = await Utils.saveImage(newImg);  
639 - if (path == null) {  
640 - File compressedFile = await FlutterNativeImage.compressImage(  
641 - pickedFile.path,  
642 - quality: 70,  
643 - percentage: 50);  
644 - path = compressedFile.path;  
645 - }  
646 - //更新本地存储,上传中展示  
647 - setState(() { 638 + if (newImg != null) {
  639 + String path = await Utils.saveImage(newImg);
  640 + if (path == null) {
  641 + File compressedFile = await FlutterNativeImage.compressImage(
  642 + pickedFile.path,
  643 + quality: 70,
  644 + percentage: 50);
  645 + path = compressedFile.path;
  646 + }
  647 + //更新本地存储,上传中展示
  648 + setState(() {
  649 + if (pickedFile != null) {
  650 + imgModel.file = File(path);
  651 + imgModel.process = 0.01;
  652 + } else {
  653 + print('No image selected.');
  654 + }
  655 + });
648 if (pickedFile != null) { 656 if (pickedFile != null) {
649 - imgModel.file = File(path);  
650 - imgModel.process = 0.01;  
651 - } else {  
652 - print('No image selected.'); 657 + _uploadImageProvider.mentou.qiniuUrl = null;
  658 + _uploadImageProvider.mentou.file = File(path);
  659 + _uploadImageProvider.mentou.path = path;
  660 + UploadImageUtil().startUploadOnly(
  661 + context, File(path), 2, true, _uploadImageProvider);
653 } 662 }
654 - });  
655 - if (pickedFile != null) {  
656 - _uploadImageProvider.mentou.qiniuUrl = null;  
657 - _uploadImageProvider.mentou.file = File(path);  
658 - _uploadImageProvider.mentou.path = path;  
659 - UploadImageUtil()  
660 - .startUploadOnly(context, File(path), 2, true, _uploadImageProvider);  
661 } 663 }
662 } 664 }
663 665
@@ -1584,6 +1584,11 @@ class Utils { @@ -1584,6 +1584,11 @@ class Utils {
1584 Uint8List result = list; 1584 Uint8List result = list;
1585 if (needResize) { 1585 if (needResize) {
1586 result = await resizeImage(list); //重置图片尺寸 1586 result = await resizeImage(list); //重置图片尺寸
  1587 + if (result == null) {
  1588 + //取消重置尺寸
  1589 + Loading.hideLoading(context);
  1590 + return null;
  1591 + }
1587 } 1592 }
1588 Uint8List resultnew = await realComporessList(result); //压缩图片 1593 Uint8List resultnew = await realComporessList(result); //压缩图片
1589 1594
@@ -1603,6 +1608,11 @@ class Utils { @@ -1603,6 +1608,11 @@ class Utils {
1603 Loading.showLoading(context); 1608 Loading.showLoading(context);
1604 Uint8List list = await downloadFile(url); //下载图片 1609 Uint8List list = await downloadFile(url); //下载图片
1605 Uint8List result = await resizeImage(list); //重置图片尺寸 1610 Uint8List result = await resizeImage(list); //重置图片尺寸
  1611 + if (result == null) {
  1612 + //取消重置尺寸
  1613 + Loading.hideLoading(context);
  1614 + return null;
  1615 + }
1606 Uint8List resultnew = await realComporessList(result); //压缩图片 1616 Uint8List resultnew = await realComporessList(result); //压缩图片
1607 1617
1608 Loading.hideLoading(context); 1618 Loading.hideLoading(context);
@@ -1685,8 +1695,8 @@ class Utils { @@ -1685,8 +1695,8 @@ class Utils {
1685 */ 1695 */
1686 //image_cropper插件,中心点裁剪固定比例的图片 1696 //image_cropper插件,中心点裁剪固定比例的图片
1687 String imgPath = await saveImage(data); 1697 String imgPath = await saveImage(data);
1688 - Uint8List afterImg = data;  
1689 - 1698 + // Uint8List afterImg = data;
  1699 + Uint8List afterImg;
1690 if (imgPath != null) { 1700 if (imgPath != null) {
1691 final croppedImage = await ImageCropper().cropImage( 1701 final croppedImage = await ImageCropper().cropImage(
1692 sourcePath: imgPath, 1702 sourcePath: imgPath,
@@ -1719,9 +1729,11 @@ class Utils { @@ -1719,9 +1729,11 @@ class Utils {
1719 ], 1729 ],
1720 ); 1730 );
1721 print(croppedImage); 1731 print(croppedImage);
1722 - File yourFile = File(croppedImage.path); 1732 + if (croppedImage != null) {
  1733 + File yourFile = File(croppedImage.path);
1723 1734
1724 - afterImg = await yourFile.readAsBytes(); 1735 + afterImg = await yourFile.readAsBytes();
  1736 + }
1725 } 1737 }
1726 1738
1727 // IMG.Image decodedImage = IMG.decodeImage(data); 1739 // IMG.Image decodedImage = IMG.decodeImage(data);