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] How to save and restore scale and offset adjustments in ExtendedImage? #725

Open
codeshong opened this issue Dec 31, 2024 · 4 comments

Comments

@codeshong
Copy link

Platforms

dart

Description

Hello, Is it possible to save the information about the scale and position(offset) adjustments made by the user before cropping an image? Additionally, is there a way to apply the saved information(scale, offset) when reloading the image later?

I want to display the user's previous edits when they reopen the image for further adjustments.

Thank you in advance.

My code

No response

Try do it

No response

@zmtzawqlp
Copy link
Member

you can get current EditActionDetails

List<EditActionDetails> get history =>

@codeshong
Copy link
Author

I'll check that value. Thank you☺️

@jacob-hutchings
Copy link

Is there any way to use the saved information when reloading the image later?

@wigojacky
Copy link

wigojacky commented Feb 16, 2025

I could only make it work with below code:

Saving the offset & scale of last edit

final editAction = editorKey.currentState?.editAction;
final screenDestinationRect = editAction?.screenDestinationRect;
double totalScale *= editAction?.totalScale ?? 1;
totalScale = clampScale(totalScale, 0, maxScale);

Retrieving the offset & scale when building the widget, then trigger rebuild

maxScale /= totalScale;
if (screenDestinationRect != null) {
    final editAction = editorKey.currentState?.editAction;
    editAction?.setScreenDestinationRect(screenDestinationRect!);
}
notifyListeners();

And use above code as postframe callback

SchedulerBinding.instance.addPostFrameCallback((_) {
    //Retrieve offset & scale
});

As screenDestinationRect would affect the size of the image, I have to do some math to the totalScale & maxScale to balance for that, keeping the maxScale unchanged.

However, this is not perfect as user would experience a 'jump' from original to the last offset/scale, so see if there is a better solution!

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

4 participants