mobile_skt/lib/util/photo_picker_util.dart

44 lines
1.6 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
import 'package:sk_base_mobile/util/media_util.dart';
import 'package:sk_base_mobile/app_theme.dart';
class PhotoPickerUtil {
showPicker({Function? callback, String title = '请选择上传方式'}) async {
return showCupertinoModalPopup(
context: Get.context!,
builder: (BuildContext ctx) {
return CupertinoActionSheet(
title: Text(title),
cancelButton: CupertinoActionSheetAction(
onPressed: () {
Get.back();
},
child: const Text(
'取消',
style: TextStyle(color: Color(0xffcdcdcd)),
)),
actions: ['拍照', '相册']
.map((item) => CupertinoActionSheetAction(
onPressed: () async {
Get.back();
XFile? pickedFile = item == '拍照'
? await MediaUtil().getImageFromCamera()
: await MediaUtil().getImageFromGallery();
if (pickedFile != null) {
if (callback != null) {
callback(pickedFile);
}
}
},
child: Text(
item,
style: const TextStyle(color: AppTheme.primaryColor),
)))
.toList(),
);
});
}
}