import 'dart:io'; import 'package:flutter/cupertino.dart'; import 'package:image_picker/image_picker.dart'; // import 'package:image_picker/image_picker.dart'; import 'package:project_telephony/utils/headers.dart'; import 'package:velocity_x/velocity_x.dart'; // import 'package:velocity_x/velocity_x.dart'; class CloudImagePicker { static Future> pickMultiImage( {required String title, double maxWidth = 1000, double maxHeight = 1000}) async { List? files = []; files = await ImagePicker().pickMultiImage(); if (files == null) { return []; } else { return files.map((e) => File(e.path)).toList(); } } static Future> pickMultiAndSingleImage( {required String title, double maxWidth = 1000, double maxHeight = 1000}) async { List? files = []; // _files = await ImagePicker().pickMultiImage(); files = await Get.bottomSheet(CupertinoActionSheet( title: title.text.isIntrinsic.make(), actions: [ CupertinoDialogAction( onPressed: () async { await ImagePicker().pickMultiImage().then((value) { if (value != null) { Get.back( result: value, ); } }); }, child: Row( children: [ const Icon(CupertinoIcons.photo), 30.wb, '相册(长按图片多选)'.text.isIntrinsic.make(), ], ), ), CupertinoDialogAction( onPressed: () async { await ImagePicker() .pickImage( source: ImageSource.camera, maxHeight: maxHeight, maxWidth: maxWidth, ) .then((value) { if (value != null) { XFile pickFile = value; List files = []; files.add(pickFile); Get.back( result: files, ); } }); }, child: Row( children: [ const Icon(CupertinoIcons.camera), 30.wb, '相机'.text.isIntrinsic.make(), ], ), ), ], cancelButton: CupertinoDialogAction( onPressed: Get.back, child: '取消'.text.isIntrinsic.make(), ), )); if (files == null) { return []; } else { return files.map((e) => File(e.path)).toList(); } } static Future pickSingleImage( {required String title, double maxWidth = 1000, double maxHeight = 1000}) async { XFile? xFile = await Get.bottomSheet(CupertinoActionSheet( title: title.text.isIntrinsic.make(), actions: [ CupertinoDialogAction( onPressed: () async { await ImagePicker() .pickImage( source: ImageSource.gallery, maxHeight: maxHeight, maxWidth: maxWidth, ) .then((value) { Get.back( result: value, ); }); }, child: Row( children: [ const Icon(CupertinoIcons.photo), 30.wb, '相册'.text.isIntrinsic.make(), ], )), CupertinoDialogAction( onPressed: () async { await ImagePicker() .pickImage( source: ImageSource.camera, maxHeight: maxHeight, maxWidth: maxWidth, ) .then((value) { Get.back( result: value, ); }); }, child: Row( children: [ const Icon(CupertinoIcons.camera), 30.wb, '相机'.text.isIntrinsic.make(), ], )), ], cancelButton: CupertinoDialogAction( onPressed: Get.back, child: '取消'.text.isIntrinsic.make(), ), )); if (xFile != null) { return File(xFile.path); } else { return null; } } }