25 lines
699 B
Dart
25 lines
699 B
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:image_cropper/image_cropper.dart';
|
|
import 'package:image_picker/image_picker.dart';
|
|
|
|
class MediaService {
|
|
static Future<File?> pickImage({required ImageSource source}) async {
|
|
final imagePicker = ImagePicker();
|
|
final XFile? pickedFile = await imagePicker.pickImage(source: source);
|
|
if (pickedFile == null) {
|
|
return null;
|
|
}
|
|
if (kIsWeb) {
|
|
return File(pickedFile.path);
|
|
}
|
|
final cropedFile = await ImageCropper.cropImage(
|
|
sourcePath: pickedFile.path,
|
|
aspectRatio: const CropAspectRatio(ratioX: 1, ratioY: 1),
|
|
compressQuality: 70,
|
|
);
|
|
return cropedFile;
|
|
}
|
|
}
|