admin
2022-03-31 36754ba47da7a3277d5be183a523c912a1dc4cef
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//图片工具
import 'package:flutter/material.dart';
import 'package:hanju/utils/ui_constant.dart';
import 'package:image_cropper/image_cropper.dart';
import 'dart:io';
import 'package:image_picker/image_picker.dart';
 
class ImageUtil{
 
  //选择并裁剪图片
  static Future<File?> selectAndCropImage() async{
    final ImagePicker _picker = ImagePicker();
    final XFile? image = await _picker.pickImage(source: ImageSource.gallery);
    ImageCropper cropper=ImageCropper();
    File? croppedFile = await cropper.cropImage(
        cropStyle:CropStyle.circle,
        sourcePath: image!.path,
        aspectRatioPresets: [
          CropAspectRatioPreset.square
        ],
        androidUiSettings: const AndroidUiSettings(
            toolbarTitle: 'Cropper',
            toolbarColor: ColorConstant.theme,
            toolbarWidgetColor: Colors.white,
            initAspectRatio: CropAspectRatioPreset.square,
            lockAspectRatio: true),
        iosUiSettings: const IOSUiSettings(
          minimumAspectRatio: 1.0,
        )
    );
    return croppedFile;
  }
 
 
 
}