0

我正在尝试从图库中挑选的图像中裁剪图像,该图像被完美地挑选,但是在尝试裁剪图像时,屏幕中似乎没有发生任何事情,并且在控制台中检测到一些问题,尽管我无法理解问题。我使用的代码来自官方 pub.dev 网站 [https://pub.dev/packages/image_cropper/example]

我的任务是:为

帮我解决这个问题,在此先感谢。

编码:

……

class _EditGalleryScreenState extends State<EditGalleryScreen> {  
  File imageFile;
  List _galleries = new List();

  @override
  void initState() {
    .....
  }

  ....
  //SOME API CALLS

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Gallery"),
      ),
      body: _galleries.isNotEmpty
          ? GridView.builder(/* DIAPLYING LIST OF IMAGES FROM API CALL */)
          : SizedBox(),

          //BUTTON TO TRIGGER IMAGE PICKER
      floatingActionButton: FloatingActionButton(
        tooltip: "Add Image",
        onPressed: () {
          _pickImage();
        },
        child: Icon(Icons.add_a_photo),
        backgroundColor: AppColors.PRIMARY_COLOR,
      ),
    );
  }

  Future<Null> _pickImage() async {
    // imageFile = await ImagePicker.pickImage(source: ImageSource.gallery); // this was deprecated so i have updated to otherone

    PickedFile imageFile = await ImagePicker().getImage(
        source: ImageSource.gallery,
        maxWidth: 500,
        maxHeight: 500,
        imageQuality: 20);

    if (imageFile != null) {
      setState(() {
        state = AppState.picked;
        debugPrint("Image Picked and State Changed");
        _cropImage();//calling CROP FUNCTION
      });
    }
  }

  Future<Null> _cropImage() async {
    debugPrint("Crop Image Called");
    File croppedFile = await ImageCropper.cropImage(
        sourcePath: imageFile.path,
        aspectRatioPresets: Platform.isAndroid
            ? [
                CropAspectRatioPreset.square,
                CropAspectRatioPreset.ratio3x2,
                CropAspectRatioPreset.original,
                CropAspectRatioPreset.ratio4x3,
                CropAspectRatioPreset.ratio16x9
              ]
            : [
                CropAspectRatioPreset.original,
                CropAspectRatioPreset.square,
                CropAspectRatioPreset.ratio3x2,
                CropAspectRatioPreset.ratio4x3,
                CropAspectRatioPreset.ratio5x3,
                CropAspectRatioPreset.ratio5x4,
                CropAspectRatioPreset.ratio7x5,
                CropAspectRatioPreset.ratio16x9
              ],
        androidUiSettings: AndroidUiSettings(
            toolbarTitle: 'Cropper',
            toolbarColor: Colors.deepOrange,
            toolbarWidgetColor: Colors.white,
            initAspectRatio: CropAspectRatioPreset.original,
            lockAspectRatio: false),
        iosUiSettings: IOSUiSettings(
          title: 'Cropper',
        ));
    if (croppedFile != null) {
      imageFile = croppedFile;
      setState(() {
        state = AppState.cropped;
      });
    }
  }
}

控制台屏幕截图

4

0 回答 0