chooyan-eng / crop_your_image

A flutter plugin which provides Crop Widget for cropping images.
https://pub.dev/packages/crop_your_image
Apache License 2.0
152 stars 135 forks source link

[web] progressIndicator not working #141

Open c-seeger opened 6 months ago

c-seeger commented 6 months ago

Since the whole library is not using web worker when starting to crop using controller.crop() the cropping blocks the main thread resulting in a frozen page. A side effect of this is that the progressIndicator did also not work on web.

maybe sth. like https://pub.dev/packages/squadron could help solving the multithreading problems for web

chooyan-eng commented 6 months ago

@c-seeger Thank you for the suggestion. As I'm not very familiar with web, let me take some time to challenge solving this. If you are in a hurry, consider overriding cropping logic with imageCropper parameter.

Crop(
  image: _imageData,
  controller: _controller,
  imageCropper: YourCustomImageCropper(),
),
class YourCustomImageCropper<Image> extends ImageCropper {
  @override
  FutureOr<Uint8List> call({
    required Image original,
    required Offset topLeft,
    required Offset bottomRight,
    ImageFormat outputFormat = ImageFormat.jpeg,
    ImageShape shape = ImageShape.rectangle,
  }) {
    // call `defaultImageCropper.call()` using some trick not to block during operation.
    // return the result of the step above.
  }
}
adamazlo commented 6 months ago

Just wanna +1 this, with larger files the UI just seems to freeze completely when cropping. Otherwise, great work with this package!

andre-ab commented 5 months ago

@c-seegerObrigado pela sugestão. Como não estou muito familiarizado com a web, deixe-me dedicar algum tempo para desafiar a solução disso. Se você estiver com pressa, considere substituir a lógica de corte pelo imageCropperparâmetro.

Crop(
  image: _imageData,
  controller: _controller,
  imageCropper: YourCustomImageCropper(),
),
class YourCustomImageCropper<Image> extends ImageCropper {
  @override
  FutureOr<Uint8List> call({
    required Image original,
    required Offset topLeft,
    required Offset bottomRight,
    ImageFormat outputFormat = ImageFormat.jpeg,
    ImageShape shape = ImageShape.rectangle,
  }) {
    // call `defaultImageCropper.call()` using some trick not to block during operation.
    // return the result of the step above.
  }
}

Undefined class 'ImageShape'. ????