opt: pick images

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2024-11-10 15:19:09 +08:00
parent 59910e275e
commit 8919d82913
5 changed files with 190 additions and 169 deletions

View File

@@ -550,30 +550,34 @@ class _CreatePanelState extends State<CreatePanel> {
EasyThrottle.throttle(
'imagePicker', const Duration(milliseconds: 500),
() async {
List<XFile> pickedFiles =
await _imagePicker.pickMultiImage(
limit: _limit,
imageQuality: 100,
);
if (pickedFiles.isNotEmpty) {
for (int i = 0; i < pickedFiles.length; i++) {
if (_pathList.length == _limit) {
SmartDialog.showToast('最多选择$_limit张图片');
if (i != 0) {
_pathStream.add(_pathList);
}
break;
} else {
_pathList.add(pickedFiles[i].path);
if (i == pickedFiles.length - 1) {
_pathStream.add(_pathList);
try {
List<XFile> pickedFiles =
await _imagePicker.pickMultiImage(
limit: _limit,
imageQuality: 100,
);
if (pickedFiles.isNotEmpty) {
for (int i = 0; i < pickedFiles.length; i++) {
if (_pathList.length == _limit) {
SmartDialog.showToast('最多选择$_limit张图片');
if (i != 0) {
_pathStream.add(_pathList);
}
break;
} else {
_pathList.add(pickedFiles[i].path);
if (i == pickedFiles.length - 1) {
_pathStream.add(_pathList);
}
}
}
if (_pathList.isNotEmpty && !_isEnable) {
_isEnable = true;
_isEnableStream.add(true);
}
}
if (_pathList.isNotEmpty && !_isEnable) {
_isEnable = true;
_isEnableStream.add(true);
}
} catch (e) {
SmartDialog.showToast(e.toString());
}
});
},

View File

@@ -448,67 +448,71 @@ class _EditProfilePageState extends State<EditProfilePage> {
}
void _pickImg() async {
XFile? pickedFile = await _imagePicker.pickImage(
source: ImageSource.gallery,
imageQuality: 100,
);
if (pickedFile != null && mounted) {
String? mimeType =
lookupMimeType(pickedFile.path)?.split('/').getOrNull(1);
if (mimeType == 'gif') {
SmartDialog.showToast('不能选GIF');
return;
}
CroppedFile? croppedFile = await ImageCropper().cropImage(
sourcePath: pickedFile.path,
uiSettings: [
AndroidUiSettings(
toolbarTitle: '裁剪',
toolbarColor: Theme.of(context).colorScheme.primary,
toolbarWidgetColor: Colors.white,
aspectRatioPresets: [
CropAspectRatioPresetCustom(),
],
lockAspectRatio: true,
hideBottomControls: true,
cropStyle: CropStyle.circle,
initAspectRatio: CropAspectRatioPresetCustom(),
),
IOSUiSettings(
title: '裁剪',
aspectRatioPresets: [
CropAspectRatioPresetCustom(),
],
cropStyle: CropStyle.circle,
aspectRatioLockEnabled: true,
resetAspectRatioEnabled: false,
aspectRatioPickerButtonHidden: true,
),
],
try {
XFile? pickedFile = await _imagePicker.pickImage(
source: ImageSource.gallery,
imageQuality: 100,
);
if (croppedFile != null) {
Request()
.post(
'/x/member/web/face/update',
queryParameters: {
'csrf': await Request.getCsrf(),
},
data: FormData.fromMap({
'dopost': 'save',
'DisplayRank': 10000,
'face': await MultipartFile.fromFile(croppedFile.path),
}),
)
.then((data) {
if (data.data['code'] == 0) {
(_loadingState as Success).response['face'] = data.data['data'];
SmartDialog.showToast('修改成功');
setState(() {});
} else {
SmartDialog.showToast(data.data['message']);
}
});
if (pickedFile != null && mounted) {
String? mimeType =
lookupMimeType(pickedFile.path)?.split('/').getOrNull(1);
if (mimeType == 'gif') {
SmartDialog.showToast('不能选GIF');
return;
}
CroppedFile? croppedFile = await ImageCropper().cropImage(
sourcePath: pickedFile.path,
uiSettings: [
AndroidUiSettings(
toolbarTitle: '裁剪',
toolbarColor: Theme.of(context).colorScheme.primary,
toolbarWidgetColor: Colors.white,
aspectRatioPresets: [
CropAspectRatioPresetCustom(),
],
lockAspectRatio: true,
hideBottomControls: true,
cropStyle: CropStyle.circle,
initAspectRatio: CropAspectRatioPresetCustom(),
),
IOSUiSettings(
title: '裁剪',
aspectRatioPresets: [
CropAspectRatioPresetCustom(),
],
cropStyle: CropStyle.circle,
aspectRatioLockEnabled: true,
resetAspectRatioEnabled: false,
aspectRatioPickerButtonHidden: true,
),
],
);
if (croppedFile != null) {
Request()
.post(
'/x/member/web/face/update',
queryParameters: {
'csrf': await Request.getCsrf(),
},
data: FormData.fromMap({
'dopost': 'save',
'DisplayRank': 10000,
'face': await MultipartFile.fromFile(croppedFile.path),
}),
)
.then((data) {
if (data.data['code'] == 0) {
(_loadingState as Success).response['face'] = data.data['data'];
SmartDialog.showToast('修改成功');
setState(() {});
} else {
SmartDialog.showToast(data.data['message']);
}
});
}
}
} catch (e) {
SmartDialog.showToast(e.toString());
}
}
}

View File

@@ -112,50 +112,54 @@ class _CreateFavPageState extends State<CreateFavPage> {
}
void _pickImg() async {
XFile? pickedFile = await _imagePicker.pickImage(
source: ImageSource.gallery,
imageQuality: 100,
);
if (pickedFile != null && mounted) {
CroppedFile? croppedFile = await ImageCropper().cropImage(
sourcePath: pickedFile.path,
uiSettings: [
AndroidUiSettings(
toolbarTitle: '裁剪',
toolbarColor: Theme.of(context).colorScheme.primary,
toolbarWidgetColor: Colors.white,
aspectRatioPresets: [
CropAspectRatioPreset.ratio16x9,
],
lockAspectRatio: true,
hideBottomControls: true,
initAspectRatio: CropAspectRatioPreset.ratio16x9,
),
IOSUiSettings(
title: '裁剪',
aspectRatioPresets: [
CropAspectRatioPreset.ratio16x9,
],
aspectRatioLockEnabled: true,
resetAspectRatioEnabled: false,
aspectRatioPickerButtonHidden: true,
),
],
try {
XFile? pickedFile = await _imagePicker.pickImage(
source: ImageSource.gallery,
imageQuality: 100,
);
if (croppedFile != null) {
MsgHttp.uploadImage(
path: croppedFile.path,
bucket: 'medialist',
dir: 'cover',
).then((data) {
if (data['status']) {
_cover = data['data']['location'];
setState(() {});
} else {
SmartDialog.showToast(data['msg']);
}
});
if (pickedFile != null && mounted) {
CroppedFile? croppedFile = await ImageCropper().cropImage(
sourcePath: pickedFile.path,
uiSettings: [
AndroidUiSettings(
toolbarTitle: '裁剪',
toolbarColor: Theme.of(context).colorScheme.primary,
toolbarWidgetColor: Colors.white,
aspectRatioPresets: [
CropAspectRatioPreset.ratio16x9,
],
lockAspectRatio: true,
hideBottomControls: true,
initAspectRatio: CropAspectRatioPreset.ratio16x9,
),
IOSUiSettings(
title: '裁剪',
aspectRatioPresets: [
CropAspectRatioPreset.ratio16x9,
],
aspectRatioLockEnabled: true,
resetAspectRatioEnabled: false,
aspectRatioPickerButtonHidden: true,
),
],
);
if (croppedFile != null) {
MsgHttp.uploadImage(
path: croppedFile.path,
bucket: 'medialist',
dir: 'cover',
).then((data) {
if (data['status']) {
_cover = data['data']['location'];
setState(() {});
} else {
SmartDialog.showToast(data['msg']);
}
});
}
}
} catch (e) {
SmartDialog.showToast(e.toString());
}
}

View File

@@ -361,27 +361,31 @@ class _ReplyPageState extends State<ReplyPage>
EasyThrottle.throttle(
'imagePicker', const Duration(milliseconds: 500),
() async {
List<XFile> pickedFiles =
await _imagePicker.pickMultiImage(
limit: _limit,
imageQuality: 100,
);
if (pickedFiles.isNotEmpty) {
for (int i = 0; i < pickedFiles.length; i++) {
if (_pathList.length == _limit) {
SmartDialog.showToast('最多选择$_limit张图片');
if (i != 0) {
_pathStream.add(_pathList);
}
break;
} else {
_pathList.add(pickedFiles[i].path);
if (i == pickedFiles.length - 1) {
SmartDialog.dismiss();
_pathStream.add(_pathList);
try {
List<XFile> pickedFiles =
await _imagePicker.pickMultiImage(
limit: _limit,
imageQuality: 100,
);
if (pickedFiles.isNotEmpty) {
for (int i = 0; i < pickedFiles.length; i++) {
if (_pathList.length == _limit) {
SmartDialog.showToast('最多选择$_limit张图片');
if (i != 0) {
_pathStream.add(_pathList);
}
break;
} else {
_pathList.add(pickedFiles[i].path);
if (i == pickedFiles.length - 1) {
SmartDialog.dismiss();
_pathStream.add(_pathList);
}
}
}
}
} catch (e) {
SmartDialog.showToast(e.toString());
}
});
},

View File

@@ -310,37 +310,42 @@ class _WhisperDetailPageState extends State<WhisperDetailPage> {
if (snapshot.data == true) {
_whisperDetailController.sendMsg();
} else {
XFile? pickedFile = await _imagePicker.pickImage(
source: ImageSource.gallery,
imageQuality: 100,
);
if (pickedFile != null) {
SmartDialog.showLoading(msg: '正在上传图片');
dynamic result = await MsgHttp.uploadBfs(
path: pickedFile.path,
biz: 'im',
try {
XFile? pickedFile = await _imagePicker.pickImage(
source: ImageSource.gallery,
imageQuality: 100,
);
if (result['status']) {
int imageSize = await File(pickedFile.path).length();
String mimeType = lookupMimeType(pickedFile.path)
?.split('/')
.getOrNull(1) ??
'png';
dynamic picMsg = {
'url': result['data']['image_url'],
'height': result['data']['image_height'],
'width': result['data']['image_width'],
'imageType': mimeType,
'original': 1,
'size': imageSize / 1024,
};
SmartDialog.showLoading(msg: '正在发送');
await _whisperDetailController.sendMsg(picMsg: picMsg);
} else {
SmartDialog.dismiss();
SmartDialog.showToast(result['msg']);
return;
if (pickedFile != null) {
SmartDialog.showLoading(msg: '正在上传图片');
dynamic result = await MsgHttp.uploadBfs(
path: pickedFile.path,
biz: 'im',
);
if (result['status']) {
int imageSize = await File(pickedFile.path).length();
String mimeType = lookupMimeType(pickedFile.path)
?.split('/')
.getOrNull(1) ??
'png';
dynamic picMsg = {
'url': result['data']['image_url'],
'height': result['data']['image_height'],
'width': result['data']['image_width'],
'imageType': mimeType,
'original': 1,
'size': imageSize / 1024,
};
SmartDialog.showLoading(msg: '正在发送');
await _whisperDetailController.sendMsg(
picMsg: picMsg);
} else {
SmartDialog.dismiss();
SmartDialog.showToast(result['msg']);
return;
}
}
} catch (e) {
SmartDialog.showToast(e.toString());
}
}
},