抖动的图像裁剪没有响应

时间:2020-11-11 06:25:04

标签: flutter flutter-dependencies flutter-image

我正在尝试从库中选取的图像中裁剪图像,图像被完美地拾取,但是在尝试裁剪图像时,屏幕上似乎没有任何反应,尽管我无法理解问题,但在控制台中检测到了一些问题。我使用的代码来自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;
      });
    }
  }
}

Screen Shot of Console

0 个答案:

没有答案