part of utils;

abstract class AssetsPicker {
  static final ImagePicker _imagePicker = ImagePicker();

  /// 获取图库
  static Future<XFile?> image({
    required BuildContext context,
    ImageSource source = ImageSource.gallery,
    double maxWidth = 512,
    double maxHeight = 512,
  }) async {
    if (!(await Access.photos())) {
      if (context.mounted) {
        CustomDialog.showAccess(
          context: context,
          content: const Text('获取相册权限'),
        );
      }
      return null;
    }
    return _imagePicker.pickImage(
      source: source,
      maxWidth: maxWidth,
      maxHeight: maxHeight,
    );
  }
  /// 拍照
  static Future<XFile?> camera({
    required BuildContext context,
    ImageSource source = ImageSource.camera,
    double maxWidth = 512,
    double maxHeight = 512,
  }) async {
    if (!(await Access.photos())) {
      if (context.mounted) {
        CustomDialog.showAccess(
          context: context,
          content: const Text('获取拍照权限'),
        );
      }
      return null;
    }
    return _imagePicker.pickImage(
      source: source,
      maxWidth: maxWidth,
      maxHeight: maxHeight,
    );
  }

}
