You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

159 lines
6.6 KiB

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
import 'package:wechat_camera_picker/wechat_camera_picker.dart';
import '../../generated/assets.dart';
class MoreOptionsView extends StatelessWidget {
final bool isVisible;
final ValueChanged<List<String>> onImageSelected;
final ValueChanged<String> onCameraSelected;
const MoreOptionsView({
required this.isVisible,
required this.onImageSelected,
required this.onCameraSelected,
super.key,
});
@override
Widget build(BuildContext context) {
return AnimatedContainer(
duration: Duration(milliseconds: 300),
height: isVisible ? 180.h : 0,
color: Colors.white,
child: isVisible
? Container(
padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 20.h),
child: Column(
children: [
SizedBox(height: 10.h),
// 第一行选项
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
// 图片/视频选项
GestureDetector(
onTap: () async{
try {
print('📷 [MoreOptionsView] 打开相册选择图片');
// 只支持选择图片
List<AssetEntity>? result = await AssetPicker.pickAssets(
context,
pickerConfig: const AssetPickerConfig(
requestType: RequestType.image, // 只支持图片
maxAssets: 9,
),
);
if (result != null && result.isNotEmpty) {
print('选择了 ${result.length} 张图片');
List<String> imagePaths = [];
for (var asset in result) {
final file = await asset.file;
if (file != null) {
print('图片路径: ${file.path}');
imagePaths.add(file.path);
}
}
// 批量发送图片
if (imagePaths.isNotEmpty) {
print('发送 ${imagePaths.length} 张图片');
onImageSelected(imagePaths);
}
}
} catch (e) {
print('❌ 选择图片失败: $e');
if (Get.isLogEnable) {
Get.log("选择图片失败: $e");
}
}
},
child: Column(
children: [
Container(
width: 60.w,
height: 60.w,
decoration: BoxDecoration(
color: Color(0xffF0F5FF),
borderRadius: BorderRadius.circular(8.w),
),
padding: EdgeInsets.all(10.w),
child: Image.asset(Assets.imagesPhoto, width: 40.w, height: 40.w),
),
SizedBox(height: 8.h),
Text(
"相册",
style: TextStyle(
fontSize: 12.sp,
color: Colors.black,
),
),
],
),
),
SizedBox(width: 40.w),
// 相机选项(只支持拍照)
GestureDetector(
onTap: () async{
try {
print('📷 [MoreOptionsView] 打开相机');
// 只支持拍照
AssetEntity? entity = await CameraPicker.pickFromCamera(
context,
pickerConfig: const CameraPickerConfig(
enableRecording: false, // 禁用录像功能
),
);
if (entity != null) {
final file = await entity.file;
if (file != null) {
print('拍摄的图片路径: ${file.path}');
onCameraSelected(file.path);
}
}
} catch (e) {
print('❌ 相机操作失败: $e');
if (Get.isLogEnable) {
Get.log("拍照失败: $e");
}
}
},
child: Column(
children: [
Container(
width: 60.w,
height: 60.w,
decoration: BoxDecoration(
color: Color(0xffF0F5FF),
borderRadius: BorderRadius.circular(8.w),
),
padding: EdgeInsets.all(10.w),
child: Image.asset(Assets.imagesCamera, width: 40.w, height: 40.w),
),
SizedBox(height: 8.h),
Text(
"相机",
style: TextStyle(
fontSize: 12.sp,
color: Colors.black,
),
),
],
),
),
],
),
],
),
)
: null,
);
}
}