Commit 2c92901135f5c3c0fb324022e6645580e6bd3b86

Authored by wdn127929
1 parent 7880d535

店铺信息页面上传闷头照片前进行裁剪为5:4

... ... @@ -12,14 +12,14 @@ if (flutterRoot == null) {
}
def flutterVersionCode = "444"
def flutterVersionCode = "445"
if (flutterVersionCode == null) {
flutterVersionCode = '444'
flutterVersionCode = '445'
}
def flutterVersionName = "4.4.4"
def flutterVersionName = "4.4.5"
if (flutterVersionName == null) {
flutterVersionName = '4.4.4'
flutterVersionName = '4.4.5'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
... ...
... ... @@ -597,9 +597,19 @@ class _StoreBaseInfoPageState extends State<StoreBaseInfoPage> {
Future _getFromPictureOrCamera(
String title, UploadImgModel imgModel, imageSource) async {
final pickedFile = await picker.getImage(source: imageSource);
//从相册选取照片后进行裁剪压缩
File yourFile = File(pickedFile.path);
Uint8List afterImg = await yourFile.readAsBytes();
Uint8List newImg = await Utils.testFromFileComporessList(context, afterImg);
String path = await Utils.saveImage(newImg);
if (path == null) {
path = pickedFile.path;
}
//更新本地存储,上传中展示
setState(() {
if (pickedFile != null) {
imgModel.file = File(pickedFile.path);
imgModel.file = File(path);
imgModel.process = 0.01;
} else {
print('No image selected.');
... ... @@ -607,119 +617,119 @@ class _StoreBaseInfoPageState extends State<StoreBaseInfoPage> {
});
if (pickedFile != null) {
_uploadImageProvider.mentou.qiniuUrl = null;
_uploadImageProvider.mentou.file = File(pickedFile.path);
_uploadImageProvider.mentou.path = pickedFile.path;
UploadImageUtil().startUploadOnly(
context, File(pickedFile.path), 2, true, _uploadImageProvider);
_uploadImageProvider.mentou.file = File(path);
_uploadImageProvider.mentou.path = path;
UploadImageUtil()
.startUploadOnly(context, File(path), 2, true, _uploadImageProvider);
}
}
///图片 头像和二维码
Widget _imageWidget(
String title, UploadImgModel model, double imgSize, double radius) {
return InkWell(
onTap: () {
Utils.getPickPermission(context, () {
_getFromPictureOrCamera(title, model, ImageSource.gallery);
}, Platform.isAndroid ? Permission.storage : Permission.photos);
},
child: Container(
margin: EdgeInsets.only(
top: ScreenUtil().setWidth(40),
left: ScreenUtil().setWidth(40),
right: ScreenUtil().setWidth(40)),
height: ScreenUtil().setWidth(imgSize * 2),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
title,
textAlign: TextAlign.left,
style: TextStyle(
color: MyColours.color_333333,
fontWeight: FontWeight.bold,
fontSize: ScreenUtil().setSp(34)),
),
Spacer(),
Stack(
children: [
InkWell(
onTap: () {
double process;
String qiniuUrl;
List<String> tempList = [];
process = _uploadImageProvider.mentou.process;
qiniuUrl = _uploadImageProvider.mentou.qiniuUrl;
if (qiniuUrl != null && qiniuUrl != '') {
tempList.add(qiniuUrl);
///没有上传完成的不可以点击
_showPhotoView(context, 0, tempList);
} else {
Utils.getPickPermission(context, () {
_getFromPictureOrCamera(
title, model, ImageSource.gallery);
},
Platform.isAndroid
? Permission.storage
: Permission.photos);
}
},
child: ClipRRect(
borderRadius:
BorderRadius.circular(ScreenUtil().setWidth(radius)),
child: model.file == null
? model.qiniuUrl != null && model.qiniuUrl != ''
? Image.network(
model.qiniuUrl,
fit: BoxFit.cover,
width: ScreenUtil().setWidth(imgSize * 2),
height: ScreenUtil().setWidth(imgSize * 2),
)
: Image.asset(
Utils.getImgPath('no_image'),
fit: BoxFit.cover,
width: ScreenUtil().setWidth(imgSize * 2),
height: ScreenUtil().setWidth(imgSize * 2),
)
: Image.file(
model.file,
fit: BoxFit.cover,
width: ScreenUtil().setWidth(imgSize * 2),
height: ScreenUtil().setWidth(imgSize * 2),
),
),
),
(model.file != null) &&
model.process != 1 &&
model.process != 0.01
? Container(
width: ScreenUtil().setWidth(imgSize * 2),
height: ScreenUtil().setWidth(imgSize * 2),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(radius),
color: Color.fromRGBO(0, 0, 0, 0.6)),
child: Center(
child: Text('上传中',
style:
TextStyle(color: MyColours.color_999999)),
),
)
: Container(),
],
),
HEmptyView(30),
Image.asset(
"assets/arr_right_gray.png",
width: ScreenUtil().setWidth(14),
height: ScreenUtil().setWidth(22),
)
],
),
));
}
// ///图片 头像和二维码
// Widget _imageWidget(
// String title, UploadImgModel model, double imgSize, double radius) {
// return InkWell(
// onTap: () {
// Utils.getPickPermission(context, () {
// _getFromPictureOrCamera(title, model, ImageSource.gallery);
// }, Platform.isAndroid ? Permission.storage : Permission.photos);
// },
// child: Container(
// margin: EdgeInsets.only(
// top: ScreenUtil().setWidth(40),
// left: ScreenUtil().setWidth(40),
// right: ScreenUtil().setWidth(40)),
// height: ScreenUtil().setWidth(imgSize * 2),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// Text(
// title,
// textAlign: TextAlign.left,
// style: TextStyle(
// color: MyColours.color_333333,
// fontWeight: FontWeight.bold,
// fontSize: ScreenUtil().setSp(34)),
// ),
// Spacer(),
// Stack(
// children: [
// InkWell(
// onTap: () {
// double process;
// String qiniuUrl;
// List<String> tempList = [];
// process = _uploadImageProvider.mentou.process;
// qiniuUrl = _uploadImageProvider.mentou.qiniuUrl;
// if (qiniuUrl != null && qiniuUrl != '') {
// tempList.add(qiniuUrl);
// ///没有上传完成的不可以点击
// _showPhotoView(context, 0, tempList);
// } else {
// Utils.getPickPermission(context, () {
// _getFromPictureOrCamera(
// title, model, ImageSource.gallery);
// },
// Platform.isAndroid
// ? Permission.storage
// : Permission.photos);
// }
// },
// child: ClipRRect(
// borderRadius:
// BorderRadius.circular(ScreenUtil().setWidth(radius)),
// child: model.file == null
// ? model.qiniuUrl != null && model.qiniuUrl != ''
// ? Image.network(
// model.qiniuUrl,
// fit: BoxFit.cover,
// width: ScreenUtil().setWidth(imgSize * 2),
// height: ScreenUtil().setWidth(imgSize * 2),
// )
// : Image.asset(
// Utils.getImgPath('no_image'),
// fit: BoxFit.cover,
// width: ScreenUtil().setWidth(imgSize * 2),
// height: ScreenUtil().setWidth(imgSize * 2),
// )
// : Image.file(
// model.file,
// fit: BoxFit.cover,
// width: ScreenUtil().setWidth(imgSize * 2),
// height: ScreenUtil().setWidth(imgSize * 2),
// ),
// ),
// ),
// (model.file != null) &&
// model.process != 1 &&
// model.process != 0.01
// ? Container(
// width: ScreenUtil().setWidth(imgSize * 2),
// height: ScreenUtil().setWidth(imgSize * 2),
// decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(radius),
// color: Color.fromRGBO(0, 0, 0, 0.6)),
// child: Center(
// child: Text('上传中',
// style:
// TextStyle(color: MyColours.color_999999)),
// ),
// )
// : Container(),
// ],
// ),
// HEmptyView(30),
// Image.asset(
// "assets/arr_right_gray.png",
// width: ScreenUtil().setWidth(14),
// height: ScreenUtil().setWidth(22),
// )
// ],
// ),
// ));
// }
///地图地址选择
Widget _select(String title, String hintText) {
... ...
... ... @@ -1168,7 +1168,7 @@ class Utils {
String _userName = "gh_487873d353b3";
String _path = "pack-cookbook/pages/index?rid=$rid&identity=2&sid=$sid";
String _description = "OneKey";
Uint8List source = await testComporessList(context, _thumbnail);
// Uint8List source = await testComporessList(context, _thumbnail);
var model = new WeChatShareMiniProgramModel(
webPageUrl: _webPageUrl,
userName: _userName,
... ... @@ -1176,10 +1176,9 @@ class Utils {
path: _path,
// thumbnail: WeChatImage.asset(Utils.getImgPath('mini_image')),
description: _description,
thumbnail: WeChatImage.binary(source)
// thumbnail: WeChatImage.binary(source)
// thumbnail: WeChatImage.network(_thumbnail)
);
thumbnail: WeChatImage.network(_thumbnail));
bool isShare = await shareToWeChat(model);
print(isShare);
Loading.hideLoading(context);
... ... @@ -1202,14 +1201,16 @@ class Utils {
String _path =
"pack-cookbook/pages/success?rid=$rid&identity=2&hasOnlyShow=1";
String _description = "OneKey";
Uint8List source = await testComporessList(context, _thumbnail);
// Uint8List source = await testComporessList(context, _thumbnail);
var model = new WeChatShareMiniProgramModel(
webPageUrl: _webPageUrl,
userName: _userName,
title: _title,
path: _path,
description: _description,
thumbnail: WeChatImage.binary(source));
thumbnail: WeChatImage.network(_thumbnail)
// thumbnail: WeChatImage.binary(source)
);
bool isShare = await shareToWeChat(model);
print(isShare);
Loading.hideLoading(context);
... ... @@ -1280,6 +1281,24 @@ class Utils {
// }
}
///本地选择 图片压缩 Uint8List -> Uint8List
static Future<Uint8List> testFromFileComporessList(
BuildContext context, Uint8List list) async {
Loading.showLoading(context);
Uint8List result = await resizeImage(list); //重置图片尺寸
Uint8List resultnew = await realComporessList(result); //压缩图片
Loading.hideLoading(context);
return resultnew;
// if (result.length < 128 * 1024) {
// return result;
// } else {
// result = await realComporessList(result);
// return result;
// }
}
/// 图片压缩 Uint8List -> Uint8List
static Future<Uint8List> testComporessList(
BuildContext context, String url) async {
... ... @@ -1371,13 +1390,34 @@ class Utils {
Uint8List afterImg = data;
if (imgPath != null) {
final croppedImage = await ImageCropper().cropImage(
sourcePath: imgPath,
cropStyle: CropStyle.rectangle,
compressQuality: 100,
compressFormat: ImageCompressFormat.jpg,
aspectRatioPresets: [CropAspectRatioPreset.ratio5x4],
// aspectRatio: const CropAspectRatio(ratioX: 0.8, ratioY: 1.0)
);
sourcePath: imgPath,
cropStyle: CropStyle.rectangle,
compressQuality: 100,
compressFormat: ImageCompressFormat.jpg,
aspectRatioPresets: [CropAspectRatioPreset.ratio5x4],
aspectRatio: const CropAspectRatio(ratioX: 5, ratioY: 4),
uiSettings: [
AndroidUiSettings(
// toolbarTitle: 'Cropper',
// toolbarColor: Colors.deepOrange,
// toolbarWidgetColor: Colors.white,
// initAspectRatio: CropAspectRatioPreset.ratio5x4,
hideBottomControls: true,
lockAspectRatio: true),
IOSUiSettings(
// title: 'Cropper',
// rotateButtonsHidden: true,
// rotateClockwiseButtonHidden: true,
resetAspectRatioEnabled: false,
doneButtonTitle: '确定',
cancelButtonTitle: '取消',
aspectRatioLockEnabled: true),
// WebUiSettings(
// context: context,
// ),
],
);
print(croppedImage);
File yourFile = File(croppedImage.path);
... ... @@ -1462,7 +1502,7 @@ class Utils {
String _path =
"pages/customer/index?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
String _description = "进入查看包间详情,转发同行好友,还可一键导航到饭店";
Uint8List source = await testComporessList(context, _thumbnail);
// Uint8List source = await testComporessList(context, _thumbnail);
//跳转小程序
var model = new WeChatShareMiniProgramModel(
... ... @@ -1471,8 +1511,8 @@ class Utils {
title: _title,
path: _path,
description: _description,
thumbnail: WeChatImage.binary(source)
// thumbnail: WeChatImage.network(_thumbnail)
// thumbnail: WeChatImage.binary(source)
thumbnail: WeChatImage.network(_thumbnail)
// thumbnail: WeChatImage.binary(image)
);
//分享链接
... ...
... ... @@ -177,7 +177,6 @@ dependencies:
flutter_ex_widget: ^0.0.7
crypto: ^3.0.1
flutter_keyboard_visibility: ^5.3.0
#
extended_text_field: ^10.1.1
image_gallery_saver: ^1.7.1
flutter_image_compress: ^1.1.3
... ...