Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[How to use] Any way to change current crop ratio programmatically, but still keeping it editable? #554

Open
ramtinq opened this issue Mar 2, 2023 · 1 comment

Comments

@ramtinq
Copy link

ramtinq commented Mar 2, 2023

Platforms

Android, iOS

Description

Here, if I change _cropAspectRatio, the widget will be rebuilt correctly, but then the user can't change the ratio freely by hand. On the other hand, if I change the _originalCropAspectRatio (of course with setState called), nothing will happen.

I want to find a way to have some clickable buttons for some default ratios, but still keep the ability for the user to change the ratio freely by hand.

                initEditorConfigHandler: (_) => EditorConfig(
                  maxScale: _maxScale,
                  cropRectPadding: const EdgeInsets.all(0.0),
                  hitTestSize: 20.0,
                  initialCropAspectRatio: _originalCropAspectRatio,
                  cropAspectRatio: _cropAspectRatio,
                  initCropRectType: InitCropRectType.imageRect,
                  editActionDetailsIsChanged: (details) {},
                ),

My code

No response

Try do it

I want to change the cropAspectRatio but still keep it freely customizable.

@ramtinq
Copy link
Author

ramtinq commented Mar 3, 2023

I'm trying different workarounds but none of them have worked so far. This one:

  void setDefaultCrop() {
    setState(() {
      _cropAspectRatio = 16 / 9;
    });
    setState(() {
      _cropAspectRatio = CropAspectRatios.custom;
    });
  }

The first time this function is called, it works fine (the current crop is reset to 16 / 9 and still editable by hand) but after that, it doesn't do anything at all! it seems somehow flutter caches the actions, and skips the first setState the next time you call this function, and just runs the second one.

making the function async and adding an await Future.delayed(const Duration(milliseconds: 1)); solves the problem but probably this is dependent on device's performance, because if we use 1 microsecond instead of 1 millisecond, it wont work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant